Karatas, FERHAT
I would love to change the world, but they won't give me the source code!
How to auto Update&Restart ClickOnce Application
28.12.2006 17:38:19 - Filed under : Windows App.
  • 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
with 0 comments

What do you think ?
Security Code 1956
Check S. Code
Name  
Email  
Home Page  
Comments