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

C# - App - Not terminating application until all forms are closed?

maxx233
32
Hello!

I have an app that starts up and has a starting form. One of the icons on this beginning Form opens a new form and lets the user give some information on a task they need to remember to do soon. Upon submitting this information, it takes the user back to the starting form, BUT also opens up another form to serve as a popup-reminder. This reminder is minimized to the system tray upon instantiation, and after 10 minutes (or the user clicking on the system-tray icon) it pops up and lets them give details about how they completed the thing it's reminding them to complete.

My problem: After the user submits the information they need to remember and they get dropped back to the beginning point, instinct says "get rid of this window, I no longer need it", and they close that mainForm. Since my App's Main() says Application.Run(mainForm) - when they close the mainForm it terminates the whole program, including the popup reminder. What I *want* is for the program not to terminate unless all windows (including the minimized popup) are closed, OR for the popup to run as a seperate App so that closing the first app doesn't affect it. Any guidance on which is better, and perhaps a nudge in the right direction? All help is appreciated!

Maxx

ps - Telling Main() to do Application.Run(formPopupReminder) after instantiating and show()ing what's currently the mainForm won't work - because they could need to do other work off that mainForm, and this would make it so that upon submitting the information in the popup-reminder, it would close the whole app. An inverse problem from what I have now ;)
Feb 14 '08 #1
4 2256
Plater
7,872 Expert 4TB
You can attach an event handler to the closeing (exiting?) event for the main form.
There you can attempt some smarts.
Such as "if the user tried to close the window, but there is a popup still active, cancel the close and instead hide the form"
That would mean you would have to do some other smarts on the popup window as well to make sure the program exits at correct time.

Another choice would be to make the main window be the window that owns that system tray icon. And maintain when to popup the reminder window and such, keeping the reminder window dumb.
That way when you close main window you can just hide it if needed and can handle all the events when the user clicks the systray or its time to be reminded, and know to close itself.
Feb 14 '08 #2
maxx233
32
Great! On the FormClosing event of my mainForm I did:

private void mainForm_FormClosing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (singleton.instance.openReminders > 0)
{
e.Cancel = true;
this.Hide();
singleton.instance.mainClosed = true;
}
}


And then on my PopupReminder form:

singleton.instance.openReminders--;
if ((singleton.instance.mainClosed == true) && (singleton.instance.openReminders < 1))
{
Application.Exit();
}


Thanks a lot!!
Feb 14 '08 #3
Plater
7,872 Expert 4TB
Nice job, your solution to that was actually a lot more simple then I had thought.
I had visions of it being much more complex.


One thing I should remind you of if you did not see it already, is the "type" of closing event (it's part of the arguments in the event handler). You should make sure to always close out when the system is trying to shutdown, otherwise it will refuse to shutdown because your program does not end.
Feb 15 '08 #4
Chrace
6
Agreed, nice clean method though the Windows shutdown should be considered. You can check on the FormClosing event whether the system is shutting down (System.Environment.HasShutdownStarted) and ignore your own e.Cancel.

My initial thought was to make the reminder an independent program but your version is cleaner in that you keep the link and single process instance.
Feb 15 '08 #5

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

Similar topics

6
by: foldface | last post by:
Hi I am doing drag and drop between controls (listview and treeview) using mouse_event. What I am after is a book/resource to explain the behaviour below. If I do the various Win32 api calls...
14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
2
by: Ron L | last post by:
I have an MDI application which opens a number of child windows, each of which could have data in a state that needs to be saved. Each child window catches its Closing event and cancels it if the...
5
by: Xarky | last post by:
Hi, I am creating a windows form, and when a specified event occurs (button click), I am hiding the windows form and opening a new windows form. When opening the new windows form and closing...
6
by: news.microsoft.com | last post by:
I have a very multi-threaded Windows Forms application. There are many BeginInvoke calls, as well as Thread/ThreadStarts. My issue is that when I quit my application there are often threads...
20
by: Peter Oliphant | last post by:
How does one launch multiple forms in an application? Using Photoshop as an example, this application seems to be composed of many 'disjoint' forms. Yet, they all seem somewhat 'active' in...
6
by: Ernesto | last post by:
I'm opening a telnet session with the subprocess call below. I then wait ten seconds and attempt to terminate the telnet window I created. Unfortuantely, the telnet window remains after the...
10
by: =?Utf-8?B?UmljaGFyZCBCeXNvdXRo?= | last post by:
Hi In my app I have a SplashScreen, a login form and a main form. On launching the app, I'd like to show the SplashScreen while reading config files and attempting a database connection. I show...
1
by: Clemente | last post by:
Hi, We have a VB.Net application that is sleeping until it receives a logoff/shutdown event. We want the application running on Vista and XP. When the application receives those events it has...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.