Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
Avatar
yagami #1
Member since Mar 2012 · 30 posts
Group memberships: Members
Show profile · Link to this post
Subject: Reconnect?
I set event for reconnect
  1. GlobalData.m_XmppClient.OnClose += new EventHandler<Matrix.EventArgs>(m_XmppClient_OnClose);
and I push the window button and then return the App, it can reconnect.
But I push the window button again and then return the App, it can not reconnect, because it wouldn't go into the m_XmppClient_OnClose.

Why??How to fix it?

Thank you~~:)
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Windows 7 does not allow apps to continue running apps in the background. When the windows button gets pressed you have to close the connection manual and wait for the OnClose event.
Avatar
yagami #3
Member since Mar 2012 · 30 posts
Group memberships: Members
Show profile · Link to this post
I write this code in the App.xaml.cs
  1.  private void Application_Deactivated(object sender, DeactivatedEventArgs e)
  2.  {
  3.        GlobalData.m_XmppClient.Close();
  4.  }
In other place, I write
  1. GlobalData.m_XmppClient.OnClose += new EventHandler<Matrix.EventArgs>(m_XmppClient_OnClose);
When I press the windows button, and then return the App, the App would go to m_XmppClient_OnClose, and reconnect.
But I press the windows button again, and return the App, the App couldn't go to m_XmppClient_OnClose!Why?@@

Thanks~
Avatar
Alex #4
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
The Close method is async. In Application_Deactivated you should wait until you get the OnClose. Otherwiese MatriX cannot dispose the connection properly. Or create a new XmppClient instance before you reconnect.
Avatar
tomlu #5
Member since Aug 2012 · 4 posts
Group memberships: Members
Show profile · Link to this post
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.

Suggestions?

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"

Call stack:
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

EDIT 2:
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, 14:22 by tomlu.
Avatar
Alex #6
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

sorry for the delay.

I cannot decode the stacktrace. I think some formatting got lost. Can you post it again or send it directly to me by email?

When the app gets terminated hard by the OS before it can properly dispose everything strange stuff can happen when it resumes.
If you could send us your small sample program which causes this crash this would be cool, then we can try to debug this. Is the crash reproducible on the emulator?

Alex
Avatar
tomlu #7
Member since Aug 2012 · 4 posts
Group memberships: Members
Show profile · Link to this post
I don't have a better stack trace than that - perhaps I'm missing debug information for the Matrix assembly?

The problem is AFAIK only reproducible on a device.

I've sent you a small sample program separately. Thanks!
Avatar
Alex #8
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
A new binary build is uploaded which should fix this problem.
yagami can you try it as well?
Avatar
tomlu #9
Member since Aug 2012 · 4 posts
Group memberships: Members
Show profile · Link to this post
The new build has a new issue. If I start the application without internet connectivity, immediately after trying to connect I get the following exception. No other events were raised by the connection.

UnauthorizedAccessException was unhandled
Invalid cross-thread access.

     System.Windows.dll!MS.Internal.XcpImports.CheckThread() + 0x21 bytes   
     System.Windows.dll!MS.Internal.XcpImports.DispatcherTimer_Stop(System.Windows.Threading.DispatcherTimer timer) + 0x5 bytes   
    System.Windows.dll!System.Windows.Threading.DispatcherTimer.Stop() + 0xd bytes   
     Matrix.dll!Matrix.XmppStream.DestroyKeepAliveTimer() + 0x17 bytes   
     Matrix.dll!Matrix.XmppStream.Close() + 0x6 bytes   
     Matrix.dll!Matrix.XmppStream.3q2mzyj4wtv734ttjnj6bnrw7kquujzy? �(object �, Matrix.ExceptionEventArgs �) + 0x1f bytes   
     Matrix.dll!Matrix.Net.BaseSocket.FireOnError(System.Exception ex) + 0x1d bytes   
     Matrix.dll!Matrix.Net.ClientSocket.�(object �, System.Net.Sockets.SocketAsyncEventArgs �) + 0x58 bytes   
     System.Net.dll!System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(System.Net.Sockets.SocketAsyncEventArgs e) + 0x17 bytes   
     System.Net.dll!System.Net.Sockets.SocketAsyncEventArgs.OnCompletedInternal(System.Net.Sockets.SocketAsyncEventArgs e) + 0x11 bytes   
     System.Net.dll!System.Net.Sockets.SocketAsyncEventArgs.FinishOperationAsyncFailure(System.Net.Sockets.SocketError socketError, int bytesTransferred, System.Net.Sockets.SocketFlags flags) + 0x38 bytes   
     System.Net.dll!System.Net.Sockets.Socket.AsyncCallback(System.IAsyncResult ar) + 0xcd bytes   
     System.Net.dll!System.Net.LazyAsyncResult.InvokeCallback(bool asyncCompletion) + 0x1b bytes   
     System.Net.dll!System.Net.Sockets.Socket.SocketAsyncRequestManager.WorkerThread.doWork() + 0x14b bytes   
     System.Net.dll!System.Net.Sockets.Socket.SocketAsyncRequestManager.WorkerThread.doWorkI(object o) + 0x6 bytes   
     mscorlib.dll!System.Threading.ThreadPool.WorkItem.WaitCallback_Context(object state) + 0x18 bytes   
     mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x63 bytes   
     mscorlib.dll!System.Threading.ThreadPool.WorkItem.doWork(object o) + 0x47 bytes   
     mscorlib.dll!System.Threading.Timer.ring() + 0x70 bytes
Avatar
Alex #10
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I was able to reproduce this error and fixed it. New build is uploaded. Thanks for reporting this issue.

Alex
Avatar
tomlu #11
Member since Aug 2012 · 4 posts
Group memberships: Members
Show profile · Link to this post
I can verify that this issue has been resolved by this fix. Thanks for the quick response.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters: