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

Restarting app after one form closes

Sl1ver
196 100+
Hi

I got a main form and a database selection form. When someone selects the select database form, a new form opens up.

I want to be able to see when that for is closed and then send a popup saying the application needs to be restarted

I need help with the following
1. Determine when formed closed
2. After pop is displayed, restart the application with the new settings

Any help or relevant tutorials would be much appreciated
Aug 25 '09 #1
11 2966
cloud255
427 Expert 256MB
Well you could show your message box in the Dispose method of the main form.
You can then call:

Expand|Select|Wrap|Line Numbers
  1. System.Windows.Forms.Application.Restart();
from the same method. You will need to create some sort of boolean value in the main form which will indicate if a restart is required. You then need to test this condition in the Dispose method or you will enter an infinite loop where the application constantly closes and restarts.

PS the Dispose method is in the formName.Designer.cs file, it is generated for you.
Aug 25 '09 #2
Sl1ver
196 100+
Appreciate the awesome answer, but is there a way to tell when my Form1 is closed that my Main program should restart or can i restart the whole application from any form?
Aug 25 '09 #3
GaryTexmo
1,501 Expert 1GB
Determining when the form is closed should be easy enough, look into delegates and event handling. You should be able to have your child form send a message to the parent form when it closes. An even easier way, actually, would be to pass a reference to the main form to your child form, then in the child form's form closing event, notify the parent in whatever way you prefer. You've got a fair amount of options here :)

As for restarting the main application, that's a little different. To my knowledge, once the application closes that's it, you've lost control. That said, if you set up a controlling loop for your application (ie, your main form isn't the entry point), then you can restart it. I suppose you technically have this in Program.cs...

Expand|Select|Wrap|Line Numbers
  1. Application.Run(new MyForm());
I've never done it myself, but in theory couldn't you do something like...

Expand|Select|Wrap|Line Numbers
  1. Application.EnableVisualStyles();
  2. Application.SetCompatibleTextRenderingDefault(false);
  3. bool restartApp = false;
  4. do
  5. {
  6.   MyForm form = new MyForm();
  7.   Application.Run(form);
  8.   restartApp = form.Restart;
  9. } while (restartApp == true);
Make a property on your main form called Restart, and have it true whenever the app needs to be restarted, false otherwise.

I hope that helps :)

*Edit: Cloud snuck a response in while I was writing... his answer is much better than mine, I didn't know about that... heh, that's why I love coming to this forum :)
Aug 25 '09 #4
tlhintoq
3,525 Expert 2GB
Form1 is closed
Can the Form1 be shown modal?

DialogResult TheResult = Form1.ShowDialog();
// execution stops until the From1 is closed and the result is returned here
// Do your settings reload or application restart
Aug 25 '09 #5
cloud255
427 Expert 256MB
@Sl1ver
As far as I know you can restart the application from any form. I'll double check this tonight when i get home and let you know.
Aug 25 '09 #6
cloud255
427 Expert 256MB
@GaryTexmo
:) Its always good to have more than one solution to a problem. Its the best thing about development: choice.
Not sure that my solution is the 'best' maybe the easiest to implement but not the most elegant.
Aug 25 '09 #7
tlhintoq
3,525 Expert 2GB
Not sure that my solution is the 'best' maybe the easiest to implement but not the most elegant.
The programmer I replaced used to require the application to be restarted when certain changes were made. Nobody thought it was a professional appearance to our company software. Reloading values and restarting "internally" while a dialog or progress bar is displayed leaves the user with a better feel.
Aug 25 '09 #8
cloud255
427 Expert 256MB
I double checked and you can restart the application from any form.

But tlhintoq has the best suggestion, if it is at all possible try to design your application in such a way that a restart is not required. If core DLLs are replaced then you will need to create an updater type application to achieve this but if only values are changing you should be able to update the data without a restart.
Aug 25 '09 #9
Sl1ver
196 100+
Your answer are much appreciated. Thanx for the great support!
Aug 26 '09 #10
PRR
750 Expert 512MB
Assuming its a windows application you can look into Form.FormClosing Event. This occurs when the form is being closed ... You can start process by passing applicationexecutable path or use Application.Restart
Expand|Select|Wrap|Line Numbers
  1. private void Form1_FormClosed(object sender, FormClosedEventArgs e)
  2.         {
  3.  
  4.             System.Diagnostics.Process.Start(Application.ExecutablePath);
  5.             //or
  6.            // Application.Restart();
  7.         }
  8.  
  9.  
Process.start i guess is better ...
Aug 27 '09 #11
Sl1ver
196 100+
Thanx for the help, I'v implemented the Application.Restart() method that works perfectly
Aug 27 '09 #12

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

Similar topics

1
by: 2D Rick | last post by:
I have a form that opens maximized and requires scrolling down to see all the textboxes. When you enter a textbox in the lower portion of the form the Enter event opens a large textbox with a large...
1
by: Chris Bruce | last post by:
In my application I need a way to distiguish between the following events: 1. When a user closes an MDI child window. 2. When the user closes the MDI parent window which subsequently closes the...
2
by: Jacek Jurkowski | last post by:
Could anybody help me to write proper code to restart my application? public static void OnRestartRequest() { ... } Restart is needed after exception handled and may occur anytime in...
3
by: Bruno Rodrigues | last post by:
Hi all I have an application in wich you can insert a new costumer, and like in Microsoft Outlook 2003, and option "Save and New". To deal this, I have an event in the edit form, that is raised...
8
by: Brian Fulford | last post by:
This is my first shot at a Winforms application in dot net. This application is mainly going to run unattended but is using a form to display current activity of the background processing. In VB6,...
3
by: Bob | last post by:
I haver a user login form (winforms app using vs2005 in VB.NET). After succesfull validayion of user I want to open a first form and close the loging form that was used, If I write If...
2
by: John | last post by:
Hi Is there a way to restart the current db i.e. it closes and then opens as if from beginning, opening start-up form and all that? Thanks Regards
2
by: polocar | last post by:
Hi, suppose that you have a C# form with two buttons, that are the classical "btnOk" and "btnCancel" (besides them, of course in the form there can be many other controls). When the user clicks...
8
AccessIdiot
by: AccessIdiot | last post by:
Please forgive as I am an Access and VB newbie. For what it's worth, here is my complete setup. Maybe it will help or maybe it will just confuse but I'll outline it anyway. I have a main form...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...

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.