Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Threading with async, await not executing the task

$
0
0

Using VS2013u2 and Xamarin 3 on Android.
Created a task in a shared class

public enum MyResults
  {  Unknown, Successs, Failed }

public Task<MyResults> MyTask()
{
   return new Task<string>(() =>
     {
        // Breakpoint here
        Return MyResults.Success;
     });
}

Then from a PCL forms viewmodel

public string MyMethod1()
{
   // this executes the task so I know the task is OK
   Task<MyResults> t = MyTask();
   t.Start();
}

public async MyResults MyMethod2()
{
   // this doesn’t execute the task
   MyResults result = await MyTask();
   return result;
}

With a breakpoint in the task; MyMethod1 works, the task gets called so I know the task is OK. However MyMethod2 hits the await then exits the method as expected to waits for the callback, it never happens. The task never executes, the breakpoint is never hit.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>