473,770 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# WinApp: AppDomain Unhandled Exception, handler does not force to close app

Shashi Sadasivan
1,435 Recognized Expert Top Contributor
Hi all,
I have got my windows app to handled any UI or unhandled exceptions.

following is the code

Expand|Select|Wrap|Line Numbers
  1. static class Program
  2.     {
  3.         /// <summary>
  4.         /// The main entry point for the application.
  5.         /// </summary>
  6.         [STAThread]
  7.         static void Main()
  8.         {
  9.             Application.EnableVisualStyles();
  10.             Application.SetCompatibleTextRenderingDefault(false);
  11.             Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
  12.  
  13.             Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
  14.             AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
  15.  
  16.             //try
  17.             //{
  18.                 Application.Run(new frmMainRibbon());
  19.  
  20.                 //Application.Run(new Login.frmMain());
  21.             //}
  22.             //catch (Exception ex)
  23.             //{
  24.             //    MessageBox.Show("Error: " + ex.Message, "Error");
  25.             //}
  26.         }
  27.  
  28.         static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  29.         {
  30.             DialogResult dr = MessageBox.Show("Exception Occoured - unhandled : \n" + ((Exception)e.ExceptionObject).Message + "\nDo You want to report this problem?", "Application Error", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
  31.  
  32.             if (dr == DialogResult.Yes)
  33.             {
  34.  
  35.             }
  36.  
  37.         }
  38.         static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
  39.         {
  40.             DialogResult dr = MessageBox.Show(e.Exception.Message + "\nDo You want to report this problem?", "Application Error", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
  41.  
  42.             if (dr == DialogResult.Yes)
  43.             {
  44.  
  45.             }
  46.         }
  47.     }
So what i did was since i did not handle an sql exception (when the database is not online) its supposed to be handled by CurrentDomain_U nhandledExcepti on

It works fine and the dialog is shown. However when the dialog is closed, the application is not forced to shut (even if i explicitly state Application.Clo se())
After the dialog box is closed by the user, windows shows the message that the application has closed unexpectedly and is looking for a resolution to this problem. Which only means that the application gave an error code to windows which is making windows look into its own solution site.

Any suggestions on how to avoid this?

thanks
Jan 18 '08 #1
1 5882
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
Update:
In the CurrentDomain_U nhandledExcepti on i tried Application.Exi t();
However that did not change anything and windows still wanted to check for a solution.

I then used Environment.Exi t(-1); and that was a solution. (it worked)

However, I have no idea about the exit codes. All i know that 0 is supposed to be a failure and 1 as a success (from my C days)
but changing this exit code dose not affect anything (even with a -1, 0 or 1) windows dosent do anything. So whats a valid exit code?
Jan 18 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3013
by: Silvia | last post by:
I have this code in web.config file <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="dllredirect"/> <codeBase href="http://localhost/dllrecirect/dllredirect.dll" /> </dependentAssembly> </assemblyBinding>
2
4825
by: Martin Lapierre | last post by:
How can I remove the default exception handler handler? When adding a custom handler, I can't get rid of the VS.NET unhandled exception dialog. Ex: AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler); MyHandler gets called AFTER the default VS.NET unhandled exception handler
5
2276
by: terry | last post by:
Hi, Question: When using Framesets and Server.Transfer in the Application_Error event handler is there a mechanism to get the error page to display in the total view of the browser not just in the offending frame? Overview: I have an application in which I am using framesets. When an Unhandled exception occurs I try to handle it
2
2339
by: guy | last post by:
In my application I have an event handler to catch unhandled exceptions, as per the MSDN documentation, however when an unhandled exception is thrown I get the Dialogue first, then the event handler catches the exception. How do I supress the dialogue? guy
5
3309
by: Samuel R. Neff | last post by:
When you have an unhandled exception in vb.net how do you view the exception information in the debugger? In C# the debugger creates a local variable that points to the exception and you can view it in one of the windows (autos or locals, don't remember which). That doesn't appear to be the case with vb.net. I also tried using the command window to inspect "Err" but that gave nothing useful (always empty).
2
6540
by: Chris Dunaway | last post by:
I am attempting to use the AppDomain.UnhandledException event in a Windows Forms app and also in a Windows Service. But the event doesn't seem to be called. In a Windows Forms app, the event IS called but only if I run the app through the IDE. If run standalone (release or debug build, it doesn't matter), the event handler is never called. In the Windows Forms app, I changed it to use the Application.ThreadException event and that...
22
3831
by: JPSutor | last post by:
when I use the AppDomain.UnLoad method (which calls the Thread.Abort method), I get the following error message AppDomain can not be unloaded because the thread 1378 can not be unwound out of it It seems to take time doing this. If I wait for about 30 seconds, it seems to get unloaded. Any ideas?
2
2182
by: Bob | last post by:
I MUST be able to trap unhandled exceptions, bring the thread to a routine that then closes the thread on which the execption occurred without closing or affecting the other threads. Think of an Interactive voice response telephone application. An unforeseen error occurs on one phone call. You terminate that phone call politely but you don't all of a sudden hang up the phone without warning on the other 400 callers that are on line at that...
4
5339
by: illegal.prime | last post by:
Hi all, I'm getting unexpected results when trying to preload assemblies into an AppDomain I'm creating. Upon creation of the AppDomain - I attach an AssemblyResolve to both my current AppDomain and the new AppDomain I create. I copy all the assemblies/dlls into a new directory and then try loading them all into the new AppDomain using the following: private void LoadAssembliesFromDirectory(AppDomain appDomain, string directory)
0
9453
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10254
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
10099
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
10036
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,...
1
7451
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
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3607
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.