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:
- Messages are sent 2 at a time.
- 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.
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