Guest User

Untitled

a guest
Jan 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. Process.Start()
  2.  
  3. ThreadPool.QueueUserWorkItem(delegate {
  4. Process process = Process.Start(startInfo);
  5. if(process.WaitForExit(timeout)) {
  6. // user exited
  7. } else {
  8. // timeout
  9. }
  10. });
  11.  
  12. public class UtilityManager
  13. {
  14. public Process UtilityProcess { get; private set; }
  15. private bool _isRunning;
  16. public UtilityManager() : this(null) {}
  17. public UtilityManager( Process process )
  18. {
  19. this. UtilityProcess = process ?? new Process();
  20. this._isRunning = false;
  21. }
  22. public void Start()
  23. {
  24. if (!_isRunning) {
  25. var startInfo = new ProcessStartInfo() {
  26. CreateNoWindow = true,
  27. UseShellExecute = true,
  28. FileName = _cmdLine,
  29. Arguments = _args
  30. };
  31. this.UtilityProcess.Start(startInfo);
  32. _isRunning = true;
  33. } else {
  34. throw new InvalidOperationException("Process already started");
  35. }
  36. }
  37.  
  38. [TestMethod]
  39. public void StartTest()
  40. {
  41. Process proc = new FakeProcess(); // May need to use a wrapper class
  42. UtilityManager manager = new UtilityManager( proc );
  43. manager.CommandLine = "command";
  44. ...
  45.  
  46. manager.Start();
  47.  
  48. Assert.IsTrue( proc.StartCalled );
  49. Assert.IsNotNull( proc.StartInfo );
  50. Assert.AreEqual( "command", proc.StartInfo.FileName );
  51. ...
  52. }
Add Comment
Please, Sign In to add comment