Continuously updating chat messages

Posted by Daniel on Stack Overflow See other posts from Stack Overflow or by Daniel
Published on 2011-01-02T23:04:38Z Indexed on 2011/01/02 23:54 UTC
Read the original article Hit count: 153

Filed under:
|

I'm creating a very simple chat application. It has an ASP.NET web page as front-end and a WCF service as back-end for storing the messages to a database.

Everything works great except one thing; when Browser A enters a chat message I want Browser B to see the message as soon as possible (yeah, I know, that's the purpose of a chat).

What I've done so far is to setup a trigger within the UpdatePanel, like this:

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="chatTimer" EventName="Tick" />
</Triggers>

which uses a timer:

<asp:Timer ID="chatTimer" runat="server" OnTick="chatTimer_Tick" Interval="1000" />

Is this the best approach or is there a better, yet simple, way to accomplish updating of messages. One drawback with this solution is that the textbox used to enter chat messages loses focus every time the Tick event runs.

Any piece of feedback or advice regarding updating of messages is appreciated.

Thank you!

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET