This required some explanation. There is a working thread that should raise some kind of event:
Task.Run(() =>
{
for(int i = 0; i < 123456789; i++)
{
... // some job
OnSomeEvent(i);
}
});
Upstream events synchronously block the task until all event handlers finish:
void OnSomeEvent(int i) => SomeEvent?.Invoke(this, new SomeEventArgs(i));
Asynchronous event growth will no longer block work (yay!)
void OnSomeEvent(int i) => Task.Run(() => SomeEvent?.Invoke(this, new SomeEventArgs(i)));
but now there is another problem: events are not received in the correct order:
OnSomeEvent(1);
OnSomeEvent(2);
OnSomeEvent(3);
...
SomeEvent += (s, e) => Console.WriteLine(e.I);
1
3
2
Question: how to implement asynchronous events that occur in the correct order?
, Dispatcher.InvokeAsync . , - . : 1) 2) , /, ? , , ?
P.S.: ContinueWhith.., . , "--", : ) ; 2) .
P.P.S.: , MCVE . , ..