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!

Restarting a C# application

Status
Not open for further replies.

Elroacho

Programmer
Apr 19, 2004
59
NZ
Hi,

I'm trying to write some code that will closed down and restart my application once it have completed a code download using the Updater application block (InProcess method scenario). I've tried the following:

Code:
//CheckUpdate is my class for checking and downloading updates. 
//Returns true if an update is waiting to be applied
if (CheckUpdates.RestartRequired == true)
   {
	Application.Exit();
    System.Diagnostics.Process.Start(Application.ExecutablePath);
   }

This performs the shutdown and restart but doesn't activate the PostActivationExitActivationProccess in between.

Any ideas welcomed!

Cheers,
Kevin

 
Why not open your app in a new thread which is contained within another thread?

when that thread exits, launch another thread if necessary.
 
How would I implement this?

Would this get around the PostActivationExitActivationProccess not starting?

Cheers,
Kevin.
 
Why restart the app? Why not just back to the starting point?

You can have a class called clsStart with a public variable called Restart. You can then set your project to start in clsStart's Main method, like so:

Code:
	public class clsStart
	{
		public static bool Restart = false;
		public clsStart(){}
		
		public static void Main()
        {
			Restart = false;
			Form1 f1 = new Form1();
			f1.ShowDialog();
			f1.Dispose();
			f1 = null;

			if (Restart == true)
			{
				Main();
			}
		}
	}
}

Then, when you need a restart, you can do something like:
clsStart.Restart = true
this.Close();
//Other logic to close dispose of other lingering objects

 
I can't see how this would shut down the allpication so the update process can kick in. The application process (as seen in task manager) need to completely close before the PostActivationExitActivationProccess can run which is what starts the deplyoment of the new updated code.

Cheers,
Kevin.
 
Cheers, I will have a read through that when I get the chance.

Thanks,
Kevin.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top