473,320 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Applications shuts down without any error message

Hi,
in a .NET 2.0 application, I'm noticing that sometimes the application
simply crashes and exists without showing any message. I have the
impression this has to do with some exceptions that are generated in a
secondary thread (if I'm not mistaken .NET 2.0 shuts down a process if
an exception is generated in a secondary thread).

How can I catch all the unhandled exception is any thread so that I
can display an error message to the user and gather more information?

Thanks
Andrea
Jul 20 '07 #1
1 1897
Hi Andrea,

Yes, starting from .Net2.0, the unhandled exception generated in worker
thread will also crash the AppDomain, while .Net1.1 CLR will just swallow
it. In this scenario, you have 2 options:
1. Use a big try...catch around all threads procedure, so that you can
catch any unhandled exceptions. Then, you may use EventLog or some other
approaches to log the exception details and terminate the proces with
Application.Exit.(It is recommended that you terminate the process)

2. You may leverage the AppDomain.UnhandledException event to monitor the
unhandled exceptions in the AppDomain and log it. There is no need for you
to terminate the process in this scenario, because
AppDomain.UnhandledException is merely a notification event, CLR will
always terminate the AppDomain. Below sample code snippet demonstrates the
logic:

void ThreadProc()
{
throw new Exception("abc");
}

private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(ThreadProc));
t.Start();
}

private void Form1_Load(object sender, EventArgs e)
{
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(CurrentDomain_Unhan dledException);
}

void CurrentDomain_UnhandledException(object sender,
UnhandledExceptionEventArgs e)
{
Exception except = e.ExceptionObject as Exception;
MessageBox.Show("Application is crashing with Stack Trace below:\n"+
except.StackTrace);
}

Additionally, Jason Clark written a good article talking about the
unhandled exceptions in .Net1.1. Although, this article only talks about
.Net1.1, much of the information is still valuable for .Net2.0:
"Unexpected Errors in Managed Applications"
http://msdn.microsoft.com/msdnmag/is...T/default.aspx

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 20 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brian | last post by:
Hello I am using version 4.0.12-nt of MySQL and when I hit the enter key rapidly I can't connect to the database. The result is a message is returned to me from mysql that says I can't connect...
385
by: Xah Lee | last post by:
Jargons of Info Tech industry (A Love of Jargons) Xah Lee, 2002 Feb People in the computing field like to spur the use of spurious jargons. The less educated they are, the more they like...
5
by: Richard | last post by:
Hi, I have a form that take some time to load due to many comboboxes and at least 8 subforms. When I filter or sort the main form I get an error message and then Access shuts down. They ask if...
1
by: Mike Hutton | last post by:
I need some help. I am trying to set up our development environment so as to make life easy for my fellow developers (none of whom have used ASP.NET or VS.NET before). We are developing our...
1
by: Steven Thomas | last post by:
I have a windows service that uses office xp automation. Here is the code --------------------------------------- Public Sub CAccessSnapShot() Try Dim objAccess As New Access.Application() Dim...
5
by: brianbasquille | last post by:
Hello all, Any reason why a program would simply shut down when a MessageBox.Show() is issued? Strange behaviour as the MessageBox never actually pops up.. but running through the debugger...
5
by: Henry Stockbridge | last post by:
Hi, I have a combo box on a form whose purpose is to add a record to the form's underlying table. There are several (16) fields that the combo box carries with it, only a few that are visible...
1
by: TC | last post by:
I'm experiencing an unusual problem. When I run a specific make-table query on a computer, that computer shuts down. The computer shuts down completely, without warning, as if a power failure...
2
by: =?Utf-8?B?YW5ub3llZCB3aXRoIHZpc3Rh?= | last post by:
I have a new Toshiba Satellite laptop. It came with Vista and IE 7. When I close an Exporer window (using the X in the corner) I get a message that says "Internet Explorer has stopped working and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.