Hi, I have a similar problem myself and have been trying to implement your suggestions.
I call Close on Deactivated, and create a new connection on Activated. If I don't wait for the OnClose in Deactivated I get socket crashes upon resume. However, if I do try to wait for the OnClose event it never fires, so the app locks up forever trying to deactivate.
EDIT: Here's the error I'm getting after resume. The repro rate is about 20% per suspend/resume.
"A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied"
Matrix.dll!Matrix.Net.ClientSocket.Send(byte data) + 0x5e bytes
Matrix.dll!Matrix.XmppStream.?(string ?) + 0x44 bytes
Matrix.dll!Matrix.XmppStream.?(string ?) + 0x25 bytes
Matrix.dll!Matrix.XmppStream.?(object ?, System.EventArgs ?) + 0x34 bytes
System.Windows.dll!MS.Internal.CoreInvokeHandler.InvokeEventHandler(int typeIndex, System.Delegate handlerDelegate, object sender, object args) + 0x1f9 bytes
System.Windows.dll!MS.Internal.JoltHelper.FireEvent(System.IntPtr unmanagedObj, System.IntPtr unmanagedObjArgs, int argsTypeIndex, int actualArgsTypeIndex, string eventName) + 0x178 bytes
I've done some further testing with a very simple test program that just sends repeated messages to itself. I think all background threads are terminated when Application_Deactivated gets called. Therefore, OnClose cannot get called until the application is resumed again, and no amount of waiting will make it so.
When I return from suspend, OnClose does generally get called pretty quickly. However, sometimes it does not. When this happens, the application will crash with the above call stack after about ten seconds.
This post was edited 2
times, last on 2012-08-21, 15:22 by tomlu