开发者

C#.net application not exiting after throwing web exception and unadvise()

开发者 https://www.devze.com 2023-03-15 19:50 出处:网络
I am developing a C# web client开发者_JS百科 application which receives the content from a web server and displays it using a brower object after successful authentication. Ideally, when ever the appl

I am developing a C# web client开发者_JS百科 application which receives the content from a web server and displays it using a brower object after successful authentication. Ideally, when ever the application is exited and it needs to unsubscribe to network connection, we should call the method Unadvise(cookie) of IConnectionPoint. But when any web exception is thrown and the application needs to be closed, the application is not responding and it is not able to exit. When I comment the method Unadvise(cookie) it is working fine and the application is exiting succesfully.

Is there a way to solve the problem without commenting Unadvise(cookie)? .


I think You can use multithreading - isolated thread for that call of unadvise, which you can kill on timeout.


It could be a problem with apartments. I'm guessing here but if the object implementing IConnectionPoint is in a STA and wants to call back on another interface implemented by your code and your code does not process a message loop (i.e. if your thread is in an MTA which is the default for .NET 2.0 and forward) then the call back to your code hangs.

Depending on the threading model of your code and the objects you are using you could try to apply STAThread to your main method.

0

精彩评论

暂无评论...
验证码 换一张
取 消