InvokeAsync Order Reliability

I have a question about invokeAsync, and let the cal order be taken as reliable ornot.

Example:

//Get Dispatcher of UI Thread
private Dispatcher _dsp = Dispatcher.CurrentDispatcher;

//Method called from non-UI Thread
private void a() {
    //Do Stuff
    b();
    _dsp.InvokeAsync(() => {
          //Do Stuff in UI Thread
    });
}

private void b() {
    //Do stuff
    _dsp.InvokeAsync(() => {
        //Do stuff in UI Thread
    });
}

Can it be taken for granted that the code in b InvokeAsync will run before the code in "InvokeAsync", since it is first placed in the UI message flow manager, or is this the case when most of the time b will be run first, but on odd circulations, can to be, on the contrary, or, even worse, to jump between them?

Basically, maybe I will have problems with these 2 calls at some point or is this normal and will reliably follow the execution order that I mentioned? If there is a chance of a problem, any ideas on how to do this well?

0
1

, - , . , , , Task, - :

Task.Factory.StartNew(() => DoSomethingWith(filePath)).ContinueWith((
    Task resultFromPrevious) => DoSomethingElseWith(resultFromPrevious),  
    TaskScheduler.FromCurrentSynchronizationContext())

TaskScheduler.FromCurrentSynchronizationContext() DoSomethingElseWith .

Task.ContinueWith Method MSDN.

0

Source: https://habr.com/ru/post/1668551/


All Articles