Reputation: 4882
How can i execute the UpdateTasklist()
Method after the SubmitWorkitem()
Method without blocking the thread?
private async void SubmitWorkitem(Workitem workitem)
{
await Task.Run(() => this.SubmitWorkitem(workitem));
//UpdateTasklist() should be executed after SubmitWorkitem() method.
//How can i achieve this without blocking the UI thread?
var locator = new ViewModelLocator();
locator.Task.UpdateTasklist();
}
EDIT:
The UpdateTasklist()
method connects to an wcf webservice and asks for all open workitems. The workitem which is submitted in the SubmitWorkitem()
Method is still part of the reply. I thought that would be because UpdateTasklist()
is executed before the submission of the workitem is done.
Note that UpdateTasklist()
is also an async method
Upvotes: 2
Views: 3814
Reputation: 1062780
Important: DO NOT WRITE ASYNC VOID
METHODS (unless you are writing an event-handler)
For the rest:
That is already what happens in your code; this is what await
means; basically, your DifferentClass.UpdateTasklist();
method happens as part of the continuation that gets invoked when and only when the first task (this.SubmitWorkitem(workitem)
) completes.
With your edit, there is a missing step: you should await
the second method, otherwise the method cannot report completion / failure (IIRC the compiler will also nag you):
private async Task SubmitWorkitem(Workitem workitem)
{
await Task.Run(() => this.SubmitWorkitem(workitem));
var locator = new ViewModelLocator();
await locator.Task.UpdateTasklist();
}
Upvotes: 5