End of QueuedTask

216
2
Jump to solution
01-03-2018 12:17 PM
Highlighted
Regular Contributor

In my code I am running some code in a QueuedTask.  After the QueuedTask code, I have some more code that seems to be getting run similtaneously to the QueuedTask, which is causing problems.

How do I stop the code from progressing until the QueuedTask is complete??

QueuedTask.Run(() =>
{

   //some code

}
); //end of QueuedTask

//more code down here, that seems to run while things are still processing in the QueuedTask

foreach()

{

   //included here is code that modifies a Windows Form that cannot run inside the QueuedTask, but needs to wait for the    QueuedTask to complete before running

}

etc.

Thanks!

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
New Contributor III

You can use the await operator

    private async Task Foo()
    {
.
.
.
      await QueuedTask.Run(() =>
.
.
.

View solution in original post

Reply
0 Kudos
2 Replies
Highlighted
New Contributor III

You can use the await operator

    private async Task Foo()
    {
.
.
.
      await QueuedTask.Run(() =>
.
.
.

View solution in original post

Reply
0 Kudos
Highlighted
Regular Contributor

Thanks Steve.  Here is what I finally did to get things working:

async private void ReloadFields()
        {
            await QueuedTask.Run(() =>
                {
                    //code here
                }
                );  //end of QueuedTask


                //More code here
               
        }
Reply
0 Kudos