I have a sample WinForms app with a WCF proxy. I am using the FromAsync to return a Task and waiting on the task to complete before i return the result:
private bool Foo() {
var proxy = new MyProxy();
var request = new ProxyRequest();
var task = Task<ReturnType>.Factory.FromAsync<ProxyRequest>(client.BeginCall, client.EndCall, request, null);
task.Wait();
return true;
}
When calling this method from a button click on the form the UI thread is blocked. Why?
Because you are explicitly waiting for the task to finish before continuing when calling
task.Wait().