c# - Windows Phone asynchronous call terminates -


i creating rest communication interface small windows phone application since can not call soap web services. interface simple , uses jsonconverter parse json responses.

code looks

    public class communicate<requesttype,resposetype> resposetype:class  requesttype :class {       public async task< resposetype> communicatesvr(requesttype _parameter,string methodname,string serverip)      {          string reqdata = jsonconvert.serializeobject(_parameter);           httprequestmessage request = new httprequestmessage(httpmethod.post, serverip+methodname);          request.content = new stringcontent(reqdata, encoding.utf8, "application/json");           httpclient client = new httpclient();          client.defaultrequestheaders              .accept.add(new mediatypewithqualityheadervalue("application/json"));           httpresponsemessage response = await client.sendasync(request, httpcompletionoption.responseheadersread);             if (response.statuscode == httpstatuscode.ok)              return jsonconvert.deserializeobject<resposetype>(await response.content.readasstringasync());          else              throw new exception("error connecting " + serverip+methodname+ " ! status: " + response.statuscode);       } } 

i facing big problem. when code reach

httpresponsemessage response = await  client.sendasync(request,httpcompletionoption.responseheadersread);             

the thread ends , terminates , application seems stop. still running not doing anything. set 2 breakpoints 1 after other , second never reached. don't what's wrong, have searched web lot did not found useful. in advance, waiting response

on output windows got following message:

the thread 0xdec has exited code 259 (0x103). thread 0x2180 has exited code 259 (0x103). 

you're calling task.wait or task<t>.result further call stack, cause deadlock explain on blog. in case, ui thread deadlock (not exit).

the best fix change wait or result await.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -