Beispiel #1
0
 private void TVRockExitedHandler(object sender, EventArgs e)
 {
     System.Threading.ThreadStart hdl = new System.Threading.ThreadStart(() =>
     {
         Task.Delay(WaitTime);
         try
         { //try find if there is a process allready running.
             string exeName     = System.IO.Path.GetFileNameWithoutExtension(this.TVRockPath);
             this.TVRockProcess = System.Diagnostics.Process.GetProcessesByName(exeName).First(x => !(x is null));
         }
         catch
         { //if not it will occor a error,so create a process and run it.
             if (this.LogToUser)
             {
                 this.TVRockProcess = new Process
                 {
                     StartInfo = new ProcessStartInfo
                     {
                         FileName        = this.TVRockPath,
                         UseShellExecute = false,
                         CreateNoWindow  = false,
                         WindowStyle     = ProcessWindowStyle.Minimized,
                         UserName        = this.UserName,
                         Password        = this.PassWrod,
                         Domain          = Environment.MachineName
                     }
                 };
                 this.TVRockProcess.Start();
             }
             else
             {
                 int pid;
                 ProcessExtensions.StartProcessAsCurrentUser(this.TVRockPath, out pid);
                 this.TVRockProcess = System.Diagnostics.Process.GetProcessById(pid);
             }
         }
         finally
         { // then attach watch mechanism
             this.TVRockProcess.EnableRaisingEvents = true;
             this.TVRockProcess.Exited += TVRockExitedHandler;
             Debug.WriteLine(string.Format("[{0}]Process is running. PID = {1}", this.TVRockProcess.ProcessName, this.TVRockProcess.Id));
             this.TVRockProcess.WaitForExit();
             Debug.WriteLine("TVRock Process found exited. Wait " + this.WaitTime.ToString() + "ms to restart.");
         }
     });
     System.Threading.Thread mthread = new System.Threading.Thread(hdl);
     mthread.Start();
 }
Beispiel #2
0
 private void SpinelExitedHandler(object sender, EventArgs e)
 {
     System.Threading.ThreadStart hdl = new System.Threading.ThreadStart(() =>
     {
         Task.Delay(this.WaitTime);
         try
         {
             string exeName     = System.IO.Path.GetFileNameWithoutExtension(this.SpinelPath);
             this.SpinelProcess = System.Diagnostics.Process.GetProcessesByName(exeName).First(x => !(x is null));
         }
         catch
         {
             if (this.LogToUser)
             {
                 this.SpinelProcess = new Process
                 {
                     StartInfo = new ProcessStartInfo
                     {
                         FileName        = this.SpinelPath,
                         UseShellExecute = false,
                         CreateNoWindow  = false,
                         WindowStyle     = ProcessWindowStyle.Minimized,
                         UserName        = this.UserName,
                         Password        = this.PassWrod
                     }
                 };
                 this.SpinelProcess.Start();
             }
             else
             {
                 int pid;
                 ProcessExtensions.StartProcessAsCurrentUser(this.SpinelPath, out pid);
                 this.SpinelProcess = System.Diagnostics.Process.GetProcessById(pid);
             }
         }
         finally
         {
             this.SpinelProcess.EnableRaisingEvents = true;
             this.SpinelProcess.Exited += SpinelExitedHandler;
             Debug.WriteLine(string.Format("[{0}]Process is running. PID = {1}", this.SpinelProcess.ProcessName, this.SpinelProcess.Id));
             this.SpinelProcess.WaitForExit();
             Debug.WriteLine("Spinel Process found exited. Wait " + this.WaitTime.ToString() + "ms to restart.");
         }
     });
     System.Threading.Thread mthread = new System.Threading.Thread(hdl);
     mthread.Start();
 }