Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Having one process run another process at timed intervals
- if(!ProcessA.isRunning)
- ProcessA.Run();
- else
- Wait Until Next Interval to try
- // Get all instances of Notepad running on the local
- // computer.
- Process [] localByName = Process.GetProcessesByName("notepad");
- var startOtherProcess = true;
- while (startOtherProcess) {
- var watchedProcess = Process.Start("MyProgram.Exe");
- watchedProcess.WaitForExit();
- if (testIfProcessingFinished) {
- startOtherProcess = false;
- }
- }
- [DllImport("user32.dll")]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool SetForegroundWindow(IntPtr hWnd);
- public void RunProcess()
- {
- bool createdNew = true;
- using (Mutex mutex = new Mutex(true, "MyApplicationName", out createdNew))
- {
- if (createdNew)
- {
- // Here you should start another process
- // if it's an *.exe, use System.Diagnostics.Process.Start("myExePath.exe");
- }
- else
- {
- Process current = Process.GetCurrentProcess();
- foreach (Process process in Process.GetProcessesByName(current.ProcessName))
- {
- if (process.Id != current.Id)
- {
- SetForegroundWindow(process.MainWindowHandle);
- break;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment