How to catch exception from thread?
I am using 开发者_如何学Goa free .net telnet component (De.Mud.Telnet), which has several asynchronous methods you can call, and the component fires events when things happen. My problem is that the component is throwing an exception and I don't know how to catch it. There's no exception event, and the exception doesn't get thrown by my method call. I'm using this component from a service, and I don't know how to trap the exception.
Source code appears to be available here. Not sure of course, but it certainly matches your problem description. Whomever wrote this code was quite clueless about how exceptions work. The callbacks are the problem, when something goes wrong they throw an ApplicationException. Those exceptions are uncatchable, the callbacks are made on a threadpool thread.
This might have worked somewhat back in the .NET 1.x days, it would simply stop working properly instead of aborting your program. At least you're ahead, you now know it isn't working properly. Given that the code does very little and that the way it works is basically unfixable, I'd have to strongly recommend you just forget about using this.
Check out nsoftware.com for a company that sells a real library.
Check the latter part of this page, it is part of a good .NET threading guide that I refer to often for threading help.
精彩评论