- In Solution Explorer, right click project - properties - publish - updates
- Check "The application should check for updates"
- Select "Before the application starts"
PS : If you don't use "The application should check for updates" then "UpdateCompleted" event doesnt works properly. public partial class Form1 : Form { System.Timers.Timer tmr = new System.Timers.Timer(); public Form1() { InitializeComponent();
tmr.Elapsed += new System.Timers.ElapsedEventHandler(tmr_Elapsed); tmr.Interval = 15000; // 15 sec. tmr.Start();
if (ApplicationDeployment.IsNetworkDeployed) { ApplicationDeployment.CurrentDeployment.UpdateCompleted += new AsyncCompletedEventHandler(CurrentDeployment_UpdateCompleted); } }
void CurrentDeployment_UpdateCompleted(object sender, AsyncCompletedEventArgs e) { Application.Restart(); }
void tmr_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (ApplicationDeployment.IsNetworkDeployed) { if (ApplicationDeployment.CurrentDeployment.CheckForUpdate()) { tmr.Stop(); ApplicationDeployment.CurrentDeployment.UpdateAsync();
StartOperation(); } } } void StartOperation() { // operations that you want } }
Related Terminology : Click Once, ApplicationDeployment class
|