Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems Closing An Application

Status
Not open for further replies.
Jan 19, 2000
57
US
Hi!

Here's my issue:

I have an application that utilizes two forms.
The first form hides itself shortly after startup, and invokes the second form.

Everything works great, except that I can't get the process to end when the user exits the application using the 'X' button in the upper-righthand corner of the second form, or the 'Close' option in the standard windows form menu in the upper-lefthand corner of the second form.

I added a File menu immediately beneath the title bar of the second form which includes an 'Exit' option. When the user clicks the 'Exit' option, I have an event that exits the application like this:

private void menuItem2_Click(object sender, System.EventArgs e)
{
this.Close();
Application.Exit();
}

This works just fine! In task manager, the application closes, as well as the associated thread.

Now, when the user uses the 'X' button in the upper-righthand corner of the form the application closes in task manager, but the thread will not end. I have added the following code to the Closing event of the form:

private void Browser_Closing(object sender, System.EventArgs e)
{
this.Close();
Application.Exit();
}

What am I doing wrong?

Any help would be appreciated.
 
In my post above, please substitute the word "process" for each instance of the word "thread". Sorry about that.
 
Three days of banging my head against the keyboard, and I figured out minutes after posting on Tek-Tips.

I added the following to the top of my code:

this.Closed += new System.EventHandler(this.Browser_Closed);

Now it works wonderfully.

Thanks anyway!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top