I'm working on WCF client app, and I facing difficulties with the await/async pattern. It seems that the line: await client.LongOperationAsync(); always blocks. As I understand, the thread supposed to exit and continue on to the Main() method and then return when the async method completes, maybe I'm wrong.
The output for the code below is (always):
Test() started
Test() error
*
*
*
...
The Test() method always completes before the context returns to main. Any thoughts would be highly appreciated.
static void Main(string[] args) { Program p = new Program(); p.Test(); while (true) { Console.WriteLine("*"); Thread.Sleep(500); } } private async Task Test() { Console.WriteLine("Test() started"); try { MySoapClient client = new MySoapClient( new BasicHttpBinding(new BasicHttpSecurityMode()), new EndpointAddress("http://badaddress")); await client.LongOperationAsync(); Console.WriteLine("Test() success"); } catch (Exception) { Console.WriteLine("Test() error"); return; } Console.WriteLine("Test() end successfully"); }