-
December 1st, 2010, 04:26 AM
#1
Restart running application (C#, VS2010, Dotnet 2.0)
Hi
I have a program that is going to autoupdate itself if there is a new version on a ftp. After the update its supposed to restart itself, here is also the problem.
I have read and tried lots of things but cant really get this to work, any ideas on how to do this would be much appreciated.
Code:
Code:
private void Form1_Load(object sender, EventArgs e)
{
// Check if we have internet access
if (IsConnected())
{
// Check FTP for a new version
if (checkIfWeNeedAUpdate())
{
// Download new version to same folder as startup and named newVikingKundTerminal.exe
if (downloadNewVersion())
{
// Set new modified datetime so we wont download new version again
updateModifiedDatetime(remoteFile);
// Restart program
restartApplication();
}
}
}
else
{
// No internet, run in offline mode
}
private void restartApplication()
{
try
{
if(File.Exists(Application.StartupPath + @"\oldVikingKundTerminal.exe"))
{
File.Delete(Application.StartupPath + @"\oldVikingKundTerminal.exe");
}
File.Move(Application.StartupPath + @"\VikingKundTerminal.exe", Application.StartupPath + @"\oldVikingKundTerminal.exe");
File.Move(Application.StartupPath + @"\newVikingKundTerminal.exe", Application.StartupPath + @"\VikingKundTerminal.exe");
this.Close();
Process.Start(Application.ExecutablePath);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Omstart av programmet", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Everything works until:
Code:
Process.Start(Application.ExecutablePath);
The error says its trying to start oldVikingKundTerminal.exe....
Suggestions/Ideas on how to accomplish this?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|