c# - why does async call LiveConnectClient.GetAsync block executing thread? -


i have windows store monogame (based on xaml monogame template in visual studio 2012) app.
when connect liveconnect, system things in background, when call liveconnectclient.getasync user info (and usually) blocks caller thread, though called using await. there way make getasync call async? maybe should create new thread call it?

here's caller code. called inside monogame draw thread (can't access main ui thread in monogame).

private static liveconnectsession session = null; private static liveauthclient liveauthclient = null; private static liveconnectclient liveconnectclient = null;  public static async task authasync() {     liveauthclient = new liveauthclient();     liveloginresult liveloginresult = await liveauthclient.initializeasync();     liveloginresult = await liveauthclient.loginasync(new list<string> { "wl.signin" });     if (liveloginresult.status == liveconnectsessionstatus.connected)     {         session = liveloginresult.session;         liveconnectclient = new liveconnectclient(session);         liveoperationresult liveoperationresult = await liveconnectclient.getasync("me");         dynamic meresult = liveoperationresult.result;         myengine.userid = meresult.id;     } } 

thanks nate diamond, i've found workaround (or maybe it's solution). trick await intialization , connect in main thread (in windows store app it's not ui thread, somehow it's main one), create thread , await getasync in it. sake of clarity i've skipped try..catch..finally , unnecessary. let draw thread work w/o freezes. here' code:

private static liveconnectsession session = null; private static liveauthclient liveauthclient = null; private static liveconnectclient liveconnectclient = null;  public static async task authasync() {     await authasyncinternal();     if (liveconnectclient != null)     {         await task.run(async () =>             {                 liveoperationresult liveoperationresult =                      await liveconnectclient.("me");                 dynamic meresult = liveoperationresult.result;                 myengine.userid = meresult.id;             });     } }  private static async task authasyncinternal() {     liveauthclient = new liveauthclient();     liveloginresult liveloginresult = await liveauthclient.initializeasync();     liveloginresult = await liveauthclient.loginasync(new list<string> { "wl.signin" });     if (liveloginresult.status == liveconnectsessionstatus.connected)     {         session = liveloginresult.session;         liveconnectclient = new liveconnectclient(session);     } } 

and here's variant windows phone 8:

private static async task authasyncinternal() {     deployment.current.dispatcher.begininvoke(async delegate()         {             liveauthclient = new liveauthclient("your client id here");             liveloginresult liveloginresult = await liveauthclient.initializeasync();             liveloginresult = await liveauthclient.loginasync(new list<string> { "wl.signin" });             if (liveloginresult.status == liveconnectsessionstatus.connected)             {                 session = liveloginresult.session;                 liveconnectclient = new liveconnectclient(session);                 await task.run(async () =>                     {                         liveoperationresult liveoperationresult =                              await liveconnectclient.("me");                         dynamic meresult = liveoperationresult.result;                         myengine.userid = meresult.id;                     });             }         }); } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -