i trying create signalr application using c# 5 async/await features, whenever code run, throw system.invalidoperationexception. here simplest code reproduce problem.
public class samplehub : hub { public task<string> getgoogle() { var http = new webclient(); return http.downloadstringtaskasync("http://www.google.com"); } }
exception details:
an asynchronous operation cannot started @ time. asynchronous operations may started within asynchronous handler or module or during events in page lifecycle. if exception occurred while executing page, ensure page marked <%@ page async=\"true\" %>.
stack trace:
at system.web.aspnetsynchronizationcontext.operationstarted() @ system.net.webclient.downloadstringasync(uri address, object usertoken) @ system.net.webclient.downloadstringtaskasync(uri address) @ system.net.webclient.downloadstringtaskasync(string address)
on client side, javascript looks this.
$.connection.hub.start().done(function () { $('#google').click(function () { var google = sample.server.getgoogle(); console.log(google); }); });
what did wrong? there workarounds? keen stick async/await patterns in c# if possible @ all.
i try replacing webclient
httpclient
. downloadstringtaskasync
kind of "bolt-on" support async
on existing eap methods, , it's eap methods signalr objecting to. httpclient
uses tap directly.
Comments
Post a Comment