Created
April 12, 2011 21:56
-
-
Save jgable/916519 to your computer and use it in GitHub Desktop.
ChatController.cs - An Async Chat Controller for MVC 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.MVC | |
public class ChatController : AsyncController | |
{ | |
[AsyncTimeout(ChatServer.MaxWaitSeconds * 1002)] | |
public void IndexAsync() | |
{ | |
AsyncManager.OutstandingOperations.Increment(); | |
ChatServer.CheckForMessagesAsync(msgs => | |
{ | |
AsyncManager.Parameters["response"] = new ChatResponse | |
{ | |
messages = msgs | |
}; | |
AsyncManager.OutstandingOperations.Decrement(); | |
}); | |
} | |
public ActionResult IndexCompleted(ChatResponse response) | |
{ | |
return Json(response); | |
} | |
[HttpPost] | |
public ActionResult New(string user, string msg) | |
{ | |
ChatServer.AddMessage(user, msg); | |
return Json(new | |
{ | |
d = 1 | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment