public ScriptJobResult GetResult() { if (!this.AsyncResult.IsCompleted) { throw new InvalidOperationException("Cannot get result because the operation has not completed yet."); } var result = new ScriptJobResult(this.ID, this.ScriptBlock, this.Args); try { result.Result = (this.Pipe.EndInvoke(this.AsyncResult)); } catch (Exception ex) { result.Error = ex; } // Dispose Pipe.Dispose(); AsyncResult = null; this.IsResultProcessed = true; return(result); }
public ScriptJobResult Stop(string reason) { if (this.AsyncResult.IsCompleted) { return(this.GetResult()); } var result = new ScriptJobResult(this.ID, this.ScriptBlock, this.Args); try { this.Pipe.Stop(); result.Error = reason; } catch (Exception ex) { result.Error = (ex.Message + reason); } // Dispose Pipe.Dispose(); AsyncResult = null; this.IsResultProcessed = true; return(result); }