private void InvokerThread(object genericArgs) { string operation = null; try { InvokeArgs args = (InvokeArgs)genericArgs; operation = args.Function; Thread.CurrentThread.Name = string.Format("InvokerThread ({0})", args.Function); Type t = SynchronousEditor.GetType(); object result = t.InvokeMember( args.Function, // name BindingFlags.InvokeMethod, // invokeAttr null, // binder SynchronousEditor, // target args.Arguments // args ); TheThread = null; State = EditState.Ready; // No state changes past this point, the callback may launch another operation CallEvent(new OperationEndedInternal(OnOperationComplete), args.Function, result); } catch (ThreadAbortException) { SynchronousEditor.Reset(); } catch (Exception ex) { TheThread = null; SynchronousEditor.Reset(); if (ex is TargetInvocationException) { ex = ex.InnerException; } State = EditState.Failed; if (operation != null && ex is ApiException) { CallEvent(new OperationFailedInternal(OnOperationFailed), operation, ex); } else { CallEvent(new ExceptionCaughtInternal(OnExceptionCaught), ex); } } finally { TheThread = null; } }
private void InvokerThread(object genericArgs) { string operation = null; try { InvokeArgs args = (InvokeArgs)genericArgs; operation = args.Function; Thread.CurrentThread.Name = string.Format("InvokerThread ({0})", args.Function); Type t = SynchronousEditor.GetType(); object result = t.InvokeMember( args.Function, // name BindingFlags.InvokeMethod, // invokeAttr null, // binder SynchronousEditor, // target args.Arguments // args ); State = EditState.Finishing; CallEvent(new OperationEndedInternal(OnOperationComplete), args.Function, result); State = EditState.Ready; } catch (ThreadAbortException) { SynchronousEditor.Reset(); //TODO: maybe, an OperationAborted event is needed? } catch (Exception ex) { SynchronousEditor.Reset(); if (ex is TargetInvocationException) { ex = ex.InnerException; } State = EditState.Failed; if (operation != null && ex is ApiException) { CallEvent(new OperationFailedInternal(OnOperationFailed), operation, ex); } else { CallEvent(new ExceptionCaughtInternal(OnExceptionCaught), ex); } } }
public void Reset() { Abort(); SynchronousEditor.Reset(); }