Esempio n. 1
0
        public Task <BenchmarkResult> Execute(CancellationToken stop)
        {
            var tcs = new TaskCompletionSource <BenchmarkResult>();

            // TODO throw if handle is not initialized
            //if (Handle == null)
            //{
            //    return Task.;
            //}

            //tcs.SetCanceled()

            Handle.Exited += (s, ea) =>
            {
                _exitCalled = true;
                tcs.SetResult(Result);
            };
            Handle.OutputDataReceived += BenchmarkOutputErrorDataReceived;
            Handle.ErrorDataReceived  += BenchmarkOutputErrorDataReceived;

            // TODO BeforeStart

            if (!Handle.Start())
            {
                // TODO maybe not throw, maybe just return failed result instead
                throw new InvalidOperationException("Could not start process: " + Handle);
            }

            // TODO AfterStart

            Handle.BeginOutputReadLine();
            Handle.BeginErrorReadLine();
            stop.Register(() =>
            {
                TryExit();
            });

            return(tcs.Task);
        }