c# - Async operation completes, but result is not send to browser -
i want implement webchat.
the backend dual wcf channel. dual channel works in console or winforms, , works on web. can @ least send , receive messages.
as base used this blog post so, async operation completes.
when debug result, see messages ready send browser.
[asynctimeout(chatserver.maxwaitseconds * 1020)] // timeout bit longer internal wait public void indexasync() { chatsession chatsession = this.getchatsession(); if (chatsession != null) { this.asyncmanager.outstandingoperations.increment(); try { chatsession.checkformessagesasync(msgs => { this.asyncmanager.parameters["response"] = new chatresponse { messages = msgs }; this.asyncmanager.outstandingoperations.decrement(); }); } catch (exception ex) { logger.errorexception("failed check messages.", ex); } } } public actionresult indexcompleted(chatresponse response) { try { if (response != null) { logger.debug("async request completed. number of messages: {0}", response.messages.count); } jsonresult retval = this.json(response); logger.debug("rendered response: {0}", retval.); return retval; } catch (exception ex) { logger.errorexception("failed rendering response.", ex); return this.json(null); } }
but nothing sent.
checking fiddler, see request never response.
[sessionstate(sessionstatebehavior.readonly)] public class chatcontroller : asynccontroller
i had set sessionstatebehaviour readonly, otherwise async operation block whole page.
edit: here checkformessagesasync:
public void checkformessagesasync(action<list<chatmessage>> onmessages) { if (onmessages == null) throw new argumentnullexception("onmessages"); task task = task.factory.startnew(state => { list<chatmessage> msgs = new list<chatmessage>(); manualreseteventslim wait = new manualreseteventslim(false); action<list<chatmessage>> callback = state action<list<chatmessage>>; if (callback != null) { idisposable subscriber = m_messages.subscribe(chatmessage => { msgs.add(chatmessage); wait.set(); }); bool success; using (subscriber) { // wait max seconds new msg success = wait.wait(timespan.fromseconds(chatserver.maxwaitseconds)); } if (success) this.safecallonmessages(callback, msgs); else this.safecallonmessages(callback, null); } }, onmessages); } private void safecallonmessages(action<list<chatmessage>> onmessages, list<chatmessage> messages) { if (onmessages != null) { if (messages == null) messages = new list<chatmessage>(); try { onmessages(messages); } catch (exception ex) { this.logger.errorexception("failed call onmessages callback.", ex); } } }
it`s same idea in refered blog post
edit2: btw, when nothing received, wait timeout comes play, reponse returns. seems crash somewhere. idea how log this?
i changed jquery request (see original blog post) post get. fixes it.
Comments
Post a Comment