473,791 Members | 2,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1913
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.Exi t.(It is recommended that you terminate the process)

2. You may leverage the AppDomain.Unhan dledException 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.Unhan dledException 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(o bject sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(Thr eadProc));
t.Start();
}

private void Form1_Load(obje ct sender, EventArgs e)
{
AppDomain.Curre ntDomain.Unhand ledException += new
UnhandledExcept ionEventHandler (CurrentDomain_ UnhandledExcept ion);
}

void CurrentDomain_U nhandledExcepti on(object sender,
UnhandledExcept ionEventArgs e)
{
Exception except = e.ExceptionObje ct as Exception;
MessageBox.Show ("Applicatio n is crashing with Stack Trace below:\n"+
except.StackTra ce);
}

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
2541
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 because the database is down. If I only hit the 'enter' key once (to execute the page that my queries are on(their are four queries on this particular web page)) my queries execute just fine. We have noticed that this only happens when we:
385
17318
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 extraneous jargons, such as in the Unix & Perl community. Unlike mathematicians, where in mathematics there are no fewer jargons but each and every one are
5
3092
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 I want to send the error report to Microsoft. Has anybody seen this type of error message and what can I do to prevent it from happening. Am I doing something illegal in my code? It used to work but I have added conditional formatting to a subform...
1
1732
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 intranet which will comprise basic content with a number of small data-driven ASP.NET applications. I need to keep things simple, so I need to avoid stuff which needs too much in-depth knowledge to work.
1
1286
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 vSQLText, vThreadName As String Try vThreadName = Thread.CurrentThread.Name cFunctions.WriteEventLog("starting report on thread: "
5
1499
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 shows it fails and shuts down at the line when the MessageBox.Show() is issued. Bear in mind i am working with GDI+
5
1890
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 to the User. When the User selects a value from the combo box, the application shuts down. Here is the code for the combo box that may lead to the problem. ============================================== Private Sub cboAddPhysician_AfterUpdate()...
1
1630
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 occurred. I can run the query without any trouble on other computers. I can also run other queries on this computer, including make-table queries which create much bigger tables. When it works (on other computers), the make-table query creates a...
2
2824
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 windows is trying to fix the problem" It thinks for a few seconds and then another box dialog box pops up and says "Internet Explorer is restarting" It then shuts down every IE window I have open and restarts. I also found that it does that...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10154
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.