473,809 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unhandled Exception when exiting app using dispose method

Hi,

I am creating a multi-winform project. Everything has been working
fine, except after I perform an update to the database and decide to
Exit the winform after the update operation is complete.

I have error handling in my code but not on the dispose method. I call
the dispose method exiting the application using the code below but
results in this error message
"An unhandled exception of type 'System.NullRef erenceException '
occurred in system.manageme nt.dll
Additional information: Object reference not set to an instance of an
object."

I am may be using the dispose method incorrectly but I can't seem to
locate the issue. Any advice or hints is greatly appreaciated.

private void mnuExit_Click(o bject sender, System.EventArg s e)
{
if (MessageBox.Sho w("Are you sure you want to exit?","Exit",
MessageBoxButto ns.YesNo) == DialogResult.Ye s)
{
this.Dispose();
}
}

protected override void Dispose( bool disposing )
{
if (!bOK)
{
if (MessageBox.Sho w("You have not updated the current data. Would you
like to before exiting?", "Exit",MessageB oxButtons.YesNo ) ==
DialogResult.Ye s)
{
return;
}
}
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

Thanks in advance

Mark

Jul 6 '06 #1
1 1918
Why don't you just use the .Close method of your form to quit the
application, and handle the Closing event to check for unsaved data?

As far as I know (but I could be wrong) you only need to dispose WinFOrms
that were used as modal dialog boxes, not for modeless forms.

Hope this helps,

Joris

"kuhrty" wrote:
Hi,

I am creating a multi-winform project. Everything has been working
fine, except after I perform an update to the database and decide to
Exit the winform after the update operation is complete.

I have error handling in my code but not on the dispose method. I call
the dispose method exiting the application using the code below but
results in this error message
"An unhandled exception of type 'System.NullRef erenceException '
occurred in system.manageme nt.dll
Additional information: Object reference not set to an instance of an
object."

I am may be using the dispose method incorrectly but I can't seem to
locate the issue. Any advice or hints is greatly appreaciated.

private void mnuExit_Click(o bject sender, System.EventArg s e)
{
if (MessageBox.Sho w("Are you sure you want to exit?","Exit",
MessageBoxButto ns.YesNo) == DialogResult.Ye s)
{
this.Dispose();
}
}

protected override void Dispose( bool disposing )
{
if (!bOK)
{
if (MessageBox.Sho w("You have not updated the current data. Would you
like to before exiting?", "Exit",MessageB oxButtons.YesNo ) ==
DialogResult.Ye s)
{
return;
}
}
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

Thanks in advance

Mark

Jul 7 '06 #2

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

Similar topics

1
536
by: Rafael | last post by:
Hi, I hope I can find some help for this problem IDE: Visual Studio.NET 2003 Developer Editio Language: C# Problem: "An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll. Additional information: Object reference not set to an instance of an object. Visual Studio's IDE is not allowing me to develop projects in C#... I've trying to create a simple Windows Forms project using Visual Studio.NET...
3
17222
by: Elp | last post by:
Hi, I've developped a Window Form C# application which main form contains several activex controls. No problems most of the time but on some machine, the application crashes when the main form is closed with a NullReferenceException caused by the DisposeAxControl which, i guess, is supposed to dispose one of my ActiveX. This is not a big problem as the application is closing anyway but i'd like to suppress this crash message. However,...
2
2313
by: Emil Astrom | last post by:
Hi! I wonder if there's a way to retrieve information about thrown, not yet handled exceptions. My situation is similar to the code below: class MySession : IDisposable { : : Dispose()
0
2184
by: Sam Barham | last post by:
I have a ListView control, for which I have overwritten the WndProc method to gain access to the WM_PAINT message and generate my own OnPaint and OnPaintBackground messages, in order to colour the columns of the listview to my liking. When a row of the listview is selected, some controls are displayed on that row of the listview (so sort of like a property list thingy). In order to get the controls (specifically buttons) to display how I...
7
2718
by: Chuck Hartman | last post by:
I have a Windows service that requests web pages from a site using an HttpWebRequest object. When I try to request a page from an ASP.NET 2 site, I get a WebException with message "The remote server returned an error: (500) Internal Server Error." I found a post that suggested to catch the WebException to retrieve the actual HttpWebResponse object for more information. The response returned is shown below. At first I thought this was a...
20
7524
by: Charles Law | last post by:
I have an application that creates a class. The class has unmanaged resources, so must end gracefully. How can I guarantee that the unmanaged resources are freed? I have looked at IDisposable, but this seems to rely on a call from the application, e.g. MyClass.Dispose()
0
1993
by: Colmeister | last post by:
I recently read Jason Clark's excellent article on Unhandled Exceptions (http://msdn.microsoft.com/msdnmag/issues/04/06/NET/default.aspx) and have attempted to incorporate the features he talks about in a new application I'm writing. However, when I try to use ThreadStart to do some work in a separate thread from my GUI, the methods Jason described don't seem to catch the exception. Take the following source code: Public Class...
1
914
by: bg_ie | last post by:
Hi, I have the following Program.cs - namespace TestFrameworkApplication { static class Program { /// <summary> /// The main entry point for the application.
3
4569
by: chandhrakv | last post by:
Event code: 3005 Event message: An unhandled exception has occurred. Event time: 11/18/2009 3:03:53 PM Event time (UTC): 11/18/2009 9:33:53 AM Event ID: ef3014ea80424b00b1bc2e7095fffe4c Event sequence: 34707 Event occurrence: 17 Event detail code: 0 Process information:
0
9603
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
10643
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
10378
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...
0
10121
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...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
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
5550
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...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4333
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

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.