In my application, which using another application (run in tray) to print receipts I need to do those three things:
- Open process when on mainApplication startup
- Close process when mainApplication closing or changing any information about printer
- Keep process alive, if it get any error
First point is quiet easy, I just simply
Process.Start("_ReceiptPrinter.exe");
And process working ;)
But now, the two other issues:
Closing process. I've tried this code:
Process[] allProcs = Process.GetProcesses(); foreach (Process proc in allProcs) { ProcessThreadCollection myThreads = proc.Threads; if (proc.ProcessName == "_ReceiptPrinter") { proc.Close(); } }
Unfortunately, I can still see icon in tray, and process is still running.
- Keep process alive. My main application is in WPF, that one from tray is written on WinForms. Maybe there is any way to handle ANY WinForm application exit event (well, any, but not this one, which just simply close it from another application), and reopen it?