There is a class pool task. I decided to rewrite the Start method in such a way that I would not call it as I had done before. Testing sending messages. It seems to work, but there are 2 problems:

  1. Messages are sent 2 at a time.
  2. Blocks the main thread.

This is the start function in the created class:

public string Start() { if (!Active) { Active = true; Task.Factory.StartNew(async () => { await Task.Run(async () => { while (Active) { await Task.Delay(50); if (ListFunc.Count != 0) { await Task.Delay(2000); string a = ListFunc[0].Result; if (ActionEndedEvent != null) ActionEndedEvent(a, ListName[0]); RemoveFromPool(0); } } }); },TaskCreationOptions.AttachedToParent); } return ""; } 

This is writing in the form mein:

  PoolManager PM = new PoolManager(); PM.Start(); PM.Add(test(Привет sjtочень"), "1237"); PM.Add(test("Привет azrhrhzrчень"), "1234"); PM.Add(test("Привеzrhrhrhzrh очень"), "1235"); 

The task itself looks like this:

  async Task<string> test(string message) { await Task.Delay(10); Messages.Send(new SendParams() { Message = message, }); return ""; } 

What is the problem I can not understand. I would be grateful for the help.

  • Eeee ... And why do you need a pool of task? They are lightweight. - VladD
  • Tasks are already based on a pool of threads, there is no point in doing another task pool. - ixSci
  • @ixSci, I know that they are based on a pool of threads, but I need to select certain groups and perform them without crossing them only with tasks from the same group. - BwehaaFox
  • one
    The problem is that you can not restart the completed Task . Unlike streams that can be reused. You have a very strange task, tell us where it came from and what you really need. - VladD
  • one
    Okay, then you don’t have a pool of tasks, but a grouping. Once you need this, is it worth looking in the direction of TPL Dataflow? There your task should be solved "more directly." - VladD

0