473,412 Members | 2,142 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,412 software developers and data experts.

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.NullReferenceException'
occurred in system.management.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(object sender, System.EventArgs e)
{
if (MessageBox.Show("Are you sure you want to exit?","Exit",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
this.Dispose();
}
}

protected override void Dispose( bool disposing )
{
if (!bOK)
{
if (MessageBox.Show("You have not updated the current data. Would you
like to before exiting?", "Exit",MessageBoxButtons.YesNo ) ==
DialogResult.Yes)
{
return;
}
}
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

Thanks in advance

Mark

Jul 6 '06 #1
1 1884
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.NullReferenceException'
occurred in system.management.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(object sender, System.EventArgs e)
{
if (MessageBox.Show("Are you sure you want to exit?","Exit",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
this.Dispose();
}
}

protected override void Dispose( bool disposing )
{
if (!bOK)
{
if (MessageBox.Show("You have not updated the current data. Would you
like to before exiting?", "Exit",MessageBoxButtons.YesNo ) ==
DialogResult.Yes)
{
return;
}
}
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
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
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...
3
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...
2
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
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...
7
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...
20
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,...
0
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...
1
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
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 ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
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...
0
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...
0
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...

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.