C
Chuck P
I am having trouble getting Application.Restart to work.
My somewhat lengthy startup code is shown below.
Interestingly enough it will work, if I display a message box that
displays Application.Application.Name.
Just displaying the messagebox or just assigning
Application.ApplicationName doesn't work.
Is there a prerequesite or failure mode when using
Application.Restart()?????? Maybe some kind of hWnd or threadID
issue?
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
try
{
if
(System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed
&& ClickOnceToolKit.UpdateAvailable())
{
ClickOnceToolKit.UpdateComplete += new
ClickOnceToolKit.UpdateCompleteEventHandler(ClickOnceToolKit_UpdateComplete);
ClickOnceToolKit.StatusUpdate += new
ClickOnceToolKit.UpdateStatusEventHandler(ClickOnceToolKit_StatusUpdate);
ClickOnceToolKit.UpdateApplication(ClickOnceToolKit.RestartMode.AutoIn3Seconds);
Application.Run();
}
else
{
Form1 f = new Form1();
Application.Run(f);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
static void ClickOnceToolKit_StatusUpdate(string UpdateText)
{
//update splash screen
}
static void ClickOnceToolKit_UpdateComplete(bool success,
Exception ex)
{
if (success)
{
//kludge won't restart without using
application.productname in messagebox.
MessageBox.Show("program.ClickOnceToolKit_UpdateComplete: updated
app, doing restart now" + Application.ProductName);
Application.Restart();
Application.Exit();
}
else
{
MessageBox.Show("program.ClickOnceToolKit_UpdateComplete: error:" +
ex.Message);
Application.Exit();
}
}
My somewhat lengthy startup code is shown below.
Interestingly enough it will work, if I display a message box that
displays Application.Application.Name.
Just displaying the messagebox or just assigning
Application.ApplicationName doesn't work.
Is there a prerequesite or failure mode when using
Application.Restart()?????? Maybe some kind of hWnd or threadID
issue?
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
try
{
if
(System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed
&& ClickOnceToolKit.UpdateAvailable())
{
ClickOnceToolKit.UpdateComplete += new
ClickOnceToolKit.UpdateCompleteEventHandler(ClickOnceToolKit_UpdateComplete);
ClickOnceToolKit.StatusUpdate += new
ClickOnceToolKit.UpdateStatusEventHandler(ClickOnceToolKit_StatusUpdate);
ClickOnceToolKit.UpdateApplication(ClickOnceToolKit.RestartMode.AutoIn3Seconds);
Application.Run();
}
else
{
Form1 f = new Form1();
Application.Run(f);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
static void ClickOnceToolKit_StatusUpdate(string UpdateText)
{
//update splash screen
}
static void ClickOnceToolKit_UpdateComplete(bool success,
Exception ex)
{
if (success)
{
//kludge won't restart without using
application.productname in messagebox.
MessageBox.Show("program.ClickOnceToolKit_UpdateComplete: updated
app, doing restart now" + Application.ProductName);
Application.Restart();
Application.Exit();
}
else
{
MessageBox.Show("program.ClickOnceToolKit_UpdateComplete: error:" +
ex.Message);
Application.Exit();
}
}