I have a couple of apps created in VWG that I’ve been looking at porting over to WiseJ. One of them is an IRC chat client using IRCDotNet for the back end. In VWG I used the SignalR WebSocket extension to handle refreshing the client with new messages/nick list changes etc. once that feature was added, but I’m not sure how to do that in WiseJ since WebSocket is built right in.
I’ve messed around with the background task sample to try and implement that functionality in WiseJ, but I haven’t figured out how to adapt it to something that doesn’t require a user input like a button press to kick off the task with Application.Start. Is there a way to call Application.Update when a new message comes in from the IRC server to make the client update?
I attached the modified ChatWindow.vb. Look for ‘ Wisej: comments.
In short, you simply need to restore the context when you want to update the client from an out-of-bound event. That is a thread that was not started by a client event therefore not knowing anything about the session and websocket connection. Once the context is restored you can update anything on the client.
We use the “using” pattern to ensure that the thread is “cleared” when the context is not needed. It’s not necessary, but it’s good practice since Wisej internally uses [ThreadStatic] context field in order to minimize lookups.
A static instance firing events. Attached is a zip of the WiseJ test app in VB I’ve been working on. It’s basically just a Window with an HTML box on it to display messages at this point.
On Form Load, it creates an instance of IrcDotNet client connection, which connects to the specified server (in the test app it’s Ustream’s IRC server.) On ClientRegistered, handlers are added for the user-specific events (mode/away/channel join/etc.), and it joins the user to the channel specified in the web.config. The channel join creates a ChatChannel object and attaches handlers for various channel-specific events such as receiving nick list changes.
Normally these would update the nick list grid, add labels for different channels, etc. but thus far I’ve kept it just to seeing if I can get the client to update with the any new messages in the HTML box so most of that is commented out. I was hoping it would be as simple as tossing Application.Update in the AddMsgtoChannel sub, but that doesn’t seem to do anything. (Edit: I also tried just using a regular label to make sure it didn’t have to do with the HTML box itself.)
Please login first to submit.