Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Process.Start()
- ThreadPool.QueueUserWorkItem(delegate {
- Process process = Process.Start(startInfo);
- if(process.WaitForExit(timeout)) {
- // user exited
- } else {
- // timeout
- }
- });
- public class UtilityManager
- {
- public Process UtilityProcess { get; private set; }
- private bool _isRunning;
- public UtilityManager() : this(null) {}
- public UtilityManager( Process process )
- {
- this. UtilityProcess = process ?? new Process();
- this._isRunning = false;
- }
- public void Start()
- {
- if (!_isRunning) {
- var startInfo = new ProcessStartInfo() {
- CreateNoWindow = true,
- UseShellExecute = true,
- FileName = _cmdLine,
- Arguments = _args
- };
- this.UtilityProcess.Start(startInfo);
- _isRunning = true;
- } else {
- throw new InvalidOperationException("Process already started");
- }
- }
- [TestMethod]
- public void StartTest()
- {
- Process proc = new FakeProcess(); // May need to use a wrapper class
- UtilityManager manager = new UtilityManager( proc );
- manager.CommandLine = "command";
- ...
- manager.Start();
- Assert.IsTrue( proc.StartCalled );
- Assert.IsNotNull( proc.StartInfo );
- Assert.AreEqual( "command", proc.StartInfo.FileName );
- ...
- }
Add Comment
Please, Sign In to add comment