EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Cleanup client thread

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
#12227
Posted: 01/27/2010 23:24:50
by Jonathan Benedicto (Basic support level)
Joined: 01/27/2010
Posts: 3

I'm running a MsgConnect C# (.NET 2) client in a thread, and want the ability to be able to restart the connection by sending a message from the server. However, when I try disposing of the components and restarting the connection, SendMessageTimeout fails with a timeout.

This is the client thread code:
Code
while (true)
{
    using (var messenger = new MCMessenger())
    {
        using (var queue = new MCQueue())
        {
            using (var transport = new MCSocketTransport())
            {
                transport.Messenger = messenger;
                transport.MessengerPort = 14555;
                transport.TransportMode = MCInetTransportMode.stmClient;
                queue.Messenger = messenger;
                queue.QueueName = "ClientTest";
                queue.OnUnhandledMessage += new MCHandleMessageEvent(queue_OnUnhandledMessage);
                transport.Active = true;

                var message = MCMessenger.CreateMessageFromText(1, 2, 3, "HELO WORLD", new ASCIIEncoding(), false);

                int msgResult;
                if (!messenger.SendMessageTimeout("Socket:" + ServerIP + ":14555|ServerTest", ref message, 1000, true, null, out msgResult))
                    throw new Exception("Failed to communicate with server '" + ServerIP + "'");

                while (true)
                {
                    messenger.WaitMessage();
                    messenger.DispatchMessages();

                    if (!KeepAliveAfterMsg)
                        break;
                }
            }
        }
    }
}


The OnUnhandledMessage event handler looks like this:
Code
void queue_OnUnhandledMessage(object Sender, MCHandleMessageEventArgs Args)
{
    Args.Message.Result = 1;
    Args.Handled = true;
    KeepAliveAfterMsg = (Args.Message.MsgCode == 0);
}


Stating the obvious, but the server is running the entire time.

I'm guessing that I'm not cleaning up the components properly. What is the correct way to do this?
#12231
Posted: 01/28/2010 00:51:21
by Eugene Mayevski (EldoS Corp.)

Try calling Dispose method of all objects.

Also, what is the reason for recreating MsgConnect components? Why not use the same set of components for activities?


Sincerely yours
Eugene Mayevski
#12240
Posted: 01/28/2010 09:09:55
by Jonathan Benedicto (Basic support level)
Joined: 01/27/2010
Posts: 3

Quote
Try calling Dispose method of all objects.

The using blocks that I have around the object creation should be doing this automatically.

Quote
Also, what is the reason for recreating MsgConnect components? Why not use the same set of components for activities?

I'm actually testing to see how long MsgConnect takes to reconnect to the server.

Jon
#12241
Posted: 01/28/2010 09:48:20
by Eugene Mayevski (EldoS Corp.)

Yes, you are right about Dispose. I missed this fact.

Reconnection is as fast as original connection - the same procedure is applied. If you don't dispose the components, it will be a bit faster because each time you create SocketTransport, 2 threads are spawned.

If you want us to investigate the problem deeper, please put the source code of your test to ZIP archive (NO Obj and Bin folders please!!!) and post it here.


Sincerely yours
Eugene Mayevski

Reply

Statistics

Topic viewed 2583 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!