novotnyllc/Zeroconf

Zeroconf.NetworkInterface.<>c__DisplayClass1_2.<<NetworkRequestAsync>b__1>d.MoveNext() in D:\a\1\s\Zeroconf\NetworkInterface.cs:line 127

poumason opened this issue · 2 comments

I use Zeroconf SDK to find devices, such as:

resolverListener = ZeroconfResolver.CreateListener(CommonParameter.ZeroConfProtocolName);
resolverListener.Error += ResolverListener_Error;
resolverListener.ServiceFound += ResolverListener_ServiceFound;
resolverListener.ServiceLost += ResolverListener_ServiceLost;

When my UWP app be mini size in the Task bar a long time, the app auto be closed. I found the HockeyApp got the exception:

InnerException
HResult:-2146232798
Name:System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
   at System.Net.Sockets.Socket.EndReceiveFrom(IAsyncResult asyncResult, EndPoint& endPoint)
   at System.Net.Sockets.UdpClient.EndReceive(IAsyncResult asyncResult, IPEndPoint& remoteEP)
   at System.Net.Sockets.UdpClient.<>c.<ReceiveAsync>b__56_1(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Zeroconf.NetworkInterface.<>c__DisplayClass1_2.<<NetworkRequestAsync>b__1>d.MoveNext() in D:\a\1\s\Zeroconf\NetworkInterface.cs:line 127
Message:Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
   at System.Net.Sockets.Socket.EndReceiveFrom(IAsyncResult asyncResult, EndPoint& endPoint)
   at System.Net.Sockets.UdpClient.EndReceive(IAsyncResult asyncResult, IPEndPoint& remoteEP)
   at System.Net.Sockets.UdpClient.<>c.<ReceiveAsync>b__56_1(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Zeroconf.NetworkInterface.<>c__DisplayClass1_2.<<NetworkRequestAsync>b__1>d.MoveNext() in D:\a\1\s\Zeroconf\NetworkInterface.cs:line 127

I believe in that case, your app, in its shutdown logic, needs to dispose the listener. That should stop the network connections gracefully.

UWP should give you an opportunity to clean-up things before it kills your app entirely.

Closing due to age.