Home
Forums
New posts
Search forums
Articles
Latest reviews
Search resources
Members
Current visitors
Newsgroups
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Home
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework
Application.ThreadException not working
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="joseph_gallagher, post: 9178767"] Hi, I have a shoddily written application that is written in 1.1 that I've ported to 2.0 and now occasionaly I get crashes which I suspect are been caused by exceptions in threads, most likely due to trying to access controls which is now stricter, I know I could just set CheckForIllegalCrossThreadCalls = false; But I'd rather like to understand a bit better about ways to handle these exceptions and diagnose them so have been playing with "Application.ThreadException" and "AppDomain.CurrentDomain.UnhandledException", the problem I have is "Application.ThreadException" never seems to fire and this is cunfusing the hell out of me. I have the following simple test code using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Threading; using System.Windows.Forms; namespace TestApp { public partial class Form1 : Form { public Form1() { InitializeComponent(); Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); } void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { MessageBox.Show("CurrentDomain_UnhandledException " + e.ExceptionObject.ToString()); } void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { MessageBox.Show("Application_ThreadException"); } private void exceptionButton_Click(object sender, EventArgs e) { Thread t = new Thread(delegate() { int zero = 0; int x = 1 / zero; }); t.IsBackground = true; t.Start(); } private void crossThread_Click(object sender, EventArgs e) { Thread t = new Thread(delegate() { crossThread.Text = "Error"; }); t.IsBackground = true; t.Start(); } } } Which is just a windows form that has 2 buttons, crossThreadButton & exceptionButton, crossThreadButton simply creates a thread that tries to access a control it shouldn't, and exceptionButton simply divides by 0 to create a exception, both cause the "AppDomain.CurrentDomain.UnhandledException" event to be fired, but niether cause the "Application.ThreadException" event to be fired which is confusing me. When should "Application.ThreadException" get called, am I missing a setting or is it only for specific situations. Also is there a way to prevent the application from exiting when there is a exception in a thread and "AppDomain.CurrentDomain.UnhandledException" is fired, In my main shoddy app I'm 99.99% sure that exceptions in threads that have a long lifetime are handled and that these problems are been caused in shortlived threads that if they fail the work will simply be picked up on the next iteration, there is a reasonable amount of manual work involved in setting up and configuring the app and loosing all this is a pain for the user, if they could be informed of the error but allowed to continue that would be a lot easier for me while I find all the causes of the problem. [/QUOTE]
Verification
Post reply
Home
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework
Application.ThreadException not working
Top