arkane-systems / Arkane.Zeroconf

A Zero Configuration Networking library for .NET.
Other
3 stars 5 forks source link

Bonjour.RegisterService.Dispose hangs #5

Closed RobertBieligIBA closed 5 years ago

RobertBieligIBA commented 6 years ago

I was trying to register and then deregister a service, but on de-register the method Dispose hangs and never comes back. Is there a solution for it?

Analysis: Problem is, that this.sdRef.Process (); in method ProcessRegister() is blocking, therefore the this.task will never finish. In Dispose this.task?.Wait (); is called which will block the application.

STL1811 commented 5 years ago

I have the same problem and to fix this issue, you can change RegisterService.cs, add variable to the class : private CancellationTokenSource cts = null; On registerAsync, add cts.Token : this.task = Task.Run (() => this.ProcessRegister ()).ContinueWith (_ => this.task = null,cts.Token) ;

On Dispose, call if (cts != null) cts.Cancel(); instead of ; this.task?.Wait () ;

cerebrate commented 5 years ago

Included in 1.2 release.