Random crashes with a .NET 2.0 app


N

nagar

I've recently upgraded my .NET 1.1 application to .NET 2.0 and,
especially under Windows Vista, my users are experiencing sudden
shutdowns. The application just quits or the standard .NET 2.0 error
message is shown (the one saying that the application has performed an
invalid operation and will be shut down).

My believe is that this may be due to background threads launching
exceptions.

In the Main() procedure I'm trapping both exceptions from the main
thread and all the other thread of the domain using:

Application.ThreadException +=new
System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

Why isn't my crashreport (which I invoke when I detect an unhandled
exception) invoked on some situations and the application just quits?

Are there any reasons why this problem seems to happen more frequently
on Vista?
I also had some reports from a couple of users of immediate crashing
on Windows Vista x64.

Thanks.
Andrea
 
Ad

Advertisements

W

Walter Wang [MSFT]

Hi Andrea,

Is this issue the same as the one you posted here:

http://msdn.microsoft.com/newsgroups/managed/Default.aspx?dg=microsoft.publi
c.dotnet.general&mid=5f593e92-2206-4b32-86ef-cee951b3067f&p=1

If it's the same issue, I'm wondering if you've seen my colleague Jeffrey's
reply there. Let me know if you intend to work in this post or the previous
one. Thanks.



Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

nagar

Thanks Walter.
I prefer to continue on this post.
I've done as suggested and in theory I should be able to catch all
excecptions that are thrown by any thread. Is that right? What
happens, though, is that some customers are getting the standard
Windows error message.

How can I be sure to be able to intercept all the error message to
display the user a message and log the information about the error?

Are there any specific issue of the .NET 2.0 with the BeginInvoke (I'm
using it it invoke an asynchronous execution without calling the
EndInvoke). Can this be the problem?

Thanks.
Andrea
 
W

Walter Wang [MSFT]

Hi Andrea,

Since BeginInvoke will use a UI thread, we will need to use
Application.ThreadException to catch the unhandled exception. The
AppDomain.UnhandledException is used to handle non UI thread exception. We
should have mentioned that earlier, sorry about that.

// Add the event handler for handling UI thread exceptions to
the event.
Application.ThreadException += new
ThreadExceptionEventHandler(Form1.Form1_UIThreadException);

// Set the unhandled exception mode to force all Windows Forms
errors to go through
// our handler.

Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)
;

// Add the event handler for handling non-UI thread exceptions
to the event.
AppDomain.CurrentDomain.UnhandledException +=
new
UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

// Runs the application.
Application.Run(new Form1());




Please refer to following documentation:

#Application.SetUnhandledExceptionMode Method (UnhandledExceptionMode)
(System.Windows.Forms)
http://msdn2.microsoft.com/en-us/library/ms157905(vs.80).aspx


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Ad

Advertisements

W

Walter Wang [MSFT]

Hi Andrea,

I'm writing to check the status of this post. Please feel free to let me
know if there's anything else unclear. Thanks.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top