private void OnClientExecutionContextStateChage(object sender, ExecutionContextStateArgs e) { switch(e.NewState) { case ContextExecutionState.Failed: var exception = e.StateObject as Exception; if(exception!=null) { MessageBox.Show(exception.ToString(),"Error", MessageBoxButton.OK, MessageBoxImage.Error); } break; default: break; } Trace.WriteLine(String.Format("New state - {0} Old state - {1}", e.NewState, e.OldState)); }
protected override void OnExecutionStateChaged(object sender, ExecutionContextStateArgs e) { base.OnExecutionStateChaged(sender, e); if(e.NewState == SharedLib.ContextExecutionState.Aborting) { if(cToken!=null && cToken.Token.CanBeCanceled) { cToken.Cancel(); } } }
protected virtual void OnExecutionStateChaged(object sender, ExecutionContextStateArgs e) { #region Local Variables var settings = this.SettingsAs<SteamLicenseManagerSettings>(); IExecutionContext context = (IExecutionContext)sender; #endregion #region Child Exit if (e.NewState == ContextExecutionState.ProcessExited) { if (settings.TerminateOnChildExit) { //get the exited process int exitedProcessId = (int)e.StateObject; //check if the child is default browser string processFileName = string.Empty; //get the file name of exited process context.TryGetProcessFileName(exitedProcessId, out processFileName); if (!String.IsNullOrWhiteSpace(processFileName)) { if (settings.IsMatch(processFileName)) { lock (this.TerminateHandle) { //start waiting termination if (!this.TerminateHandle.WaitingTermination) { //set waiting flag this.TerminateHandle.WaitingTermination = true; //assign triggered proces file name this.TerminateHandle.TerminatingProcesName = processFileName; //reset wait handle this.TerminateHandle.Reset(); //async begin wating Action<IExecutionContext> del = new Action<IExecutionContext>(WaitForTerminateWorker); del.BeginInvoke(context, WaitForTerminateCallback, del); } } } } } } #endregion #region Child Created else if (e.NewState == ContextExecutionState.ProcessCreated) { if (settings.TerminateOnChildExit) { //get the exited process int startedProcessId = (int)e.StateObject; //create process file name string processFileName = string.Empty; //get process name or process file name context.TryGetProcessFileName(startedProcessId, out processFileName); if (!String.IsNullOrWhiteSpace(processFileName)) { //validate process name if (settings.IsMatch(processFileName)) { lock (this.TerminateHandle) { //reset waiting if (this.TerminateHandle.WaitingTermination) { this.TerminateHandle.WaitingTermination = false; this.TerminateHandle.Set(); } } } } } } #endregion #region Finished else if (e.NewState == ContextExecutionState.Finalized | e.NewState == ContextExecutionState.Destroyed | e.NewState == ContextExecutionState.Released) { context.ExecutionStateChaged -= OnExecutionStateChaged; } #endregion }
private void OnExecutionStateChaged(object sender, ExecutionContextStateArgs e) { switch (e.NewState) { #region Process Created case ContextExecutionState.ProcessCreated: //check if we are already waiting for process if (!this.IsWaiting && e.StateObject is int) { int processId = (int)e.StateObject; try { //get newly created process var createdProcess = Process.GetProcessById(processId); if (String.Compare(createdProcess.ProcessName, this.TargetProcessName, true) == 0) { //set target process id. will help identify exit this.TargetProcessId = processId; //we are now waiting for process window this.IsWaiting = true; //create action var action = new Action<Process>(OnWait); //invoke action action.BeginInvoke(createdProcess, OnWaitCallBack, action); } } catch (ArgumentException) { //process exited } } break; #endregion #region Process Exited case ContextExecutionState.ProcessExited: if (e.StateObject is int && (int)e.StateObject == this.TargetProcessId) { this.OnFinalizePlugin(); } break; #endregion #region Finalization case ContextExecutionState.Aborted: case ContextExecutionState.Destroyed: case ContextExecutionState.Released: case ContextExecutionState.Failed: case ContextExecutionState.Finalized: this.OnFinalizePlugin(); break; default: break; #endregion } }