private void btnStartService_Click(object sender, EventArgs e)
 {
     new Thread(() =>
     {
         try
         {
             Server.Stop("Started Windows Service");
             WebDAVService.StartService();
         }
         catch (InvalidOperationException ex)
         {
             MessageBox.Show("Could not start service. Make sure you run the server as a privileged user (e.g. Administrator).", "Failed to start Windows Service");
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.ToString());
         }
     }).Start();
 }
        private void RefreshLog()
        {
            lock (txtLog)
            {
                if (StartServerAfterServiceStopped && !WebDAVService.Running)
                {
                    StartServerAfterServiceStopped = false;
                    Server.Restart();
                }

                if (StartServiceAfterServiceStopped && !WebDAVService.Running)
                {
                    StartServiceAfterServiceStopped = false;
                    WebDAVService.StartService();
                }

                UpdateButtons();
                txtLog.Text = Server.Statistics + Environment.NewLine + Server.LogMessages;
            }
        }
        private void btnInstall_Click(object sender, EventArgs e)
        {
            new Thread(() =>
            {
                Server.Stop("Installed Windows Service");

                string executable = Assembly.GetAssembly(typeof(WebDAVServer)).Location;

                try
                {
                    ManagedInstallerClass.InstallHelper(new[] { "/i", executable });
                    WebDAVService.StartService();
                }
                catch (InvalidOperationException ex)
                {
                    MessageBox.Show("Could not install service. Make sure you run the server as a privileged user (e.g. Administrator).", "Failed to install Windows Service");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }).Start();
        }