internal static IInvokeAsyncResult BeginInvokeMethod(VirtualMachine vm, ThreadMirror thread, MethodMirror method, Value this_obj, IList <Value> arguments, InvokeOptions options, AsyncCallback callback, object state) { if (thread == null) { throw new ArgumentNullException("thread"); } if (method == null) { throw new ArgumentNullException("method"); } if (arguments == null) { arguments = new Value [0]; } InvokeFlags f = InvokeFlags.NONE; if ((options & InvokeOptions.DisableBreakpoints) != 0) { f |= InvokeFlags.DISABLE_BREAKPOINTS; } if ((options & InvokeOptions.SingleThreaded) != 0) { f |= InvokeFlags.SINGLE_THREADED; } InvokeAsyncResult r = new InvokeAsyncResult { AsyncState = state, AsyncWaitHandle = new ManualResetEvent(false), VM = vm, Thread = thread, Callback = callback }; r.ID = vm.conn.VM_BeginInvokeMethod(thread.Id, method.Id, this_obj != null ? vm.EncodeValue(this_obj) : vm.EncodeValue(vm.CreateValue(null)), vm.EncodeValues(arguments), f, InvokeCB, r); return(r); }
// This is called when the result of an invoke is received static void InvokeMultipleCB(ValueImpl v, ValueImpl exc, ErrorCode error, object state) { var r = (InvokeAsyncResult)state; Interlocked.Decrement(ref r.NumPending); if (r.NumPending == 0) { r.IsCompleted = true; ((ManualResetEvent)r.AsyncWaitHandle).Set(); } // Have to pass another asyncresult to the callback since multiple threads can execute it concurrently with results of multiple invocations var r2 = new InvokeAsyncResult { AsyncState = r.AsyncState, AsyncWaitHandle = null, VM = r.VM, Thread = r.Thread, Callback = r.Callback, IsCompleted = true }; if (error != 0) { r2.ErrorCode = error; } else { r2.Value = v; r2.Exception = exc; } r.Callback.BeginInvoke(r2, null, null); }
// This is called when the result of an invoke is received static void InvokeCB(ValueImpl v, ValueImpl exc, ValueImpl out_this, ValueImpl[] out_args, ErrorCode error, object state) { InvokeAsyncResult r = (InvokeAsyncResult)state; if (error != 0) { r.ErrorCode = error; } else { r.Value = v; r.Exception = exc; } r.OutThis = out_this; r.OutArgs = out_args; r.IsCompleted = true; ((ManualResetEvent)r.AsyncWaitHandle).Set(); if (r.Callback != null) { r.Callback.BeginInvoke(r, null, null); } }
static void InvokeComplete(IAsyncResult resultParameter) { if (resultParameter.CompletedSynchronously) { return; } InvokeAsyncResult invokeResult = resultParameter.AsyncState as InvokeAsyncResult; Fx.Assert(invokeResult != null, "Async state should have been of type InvokeAsyncResult."); try { invokeResult.returnValue = invokeResult.invoker.innerInvoker.InvokeEnd(invokeResult.serviceInstance, out invokeResult.outputs, resultParameter); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } ServiceErrorHandler.MarkException(e); invokeResult.completionException = e; } finally { if (invokeResult.DoFinish()) { invokeResult.Complete(false, invokeResult.completionException); } } }
static void StartComplete(IAsyncResult resultParameter) { if (resultParameter.CompletedSynchronously) { return; } InvokeAsyncResult invokeResult = resultParameter.AsyncState as InvokeAsyncResult; Fx.Assert(invokeResult != null, "Async state should have been of type InvokeAsyncResult."); try { invokeResult.serviceInstance = invokeResult.durableInstance.EndStartOperation(resultParameter); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } invokeResult.Complete(false, e); return; } if (invokeResult.DoInvoke()) { invokeResult.Complete(false, invokeResult.completionException); } }
static void FinishComplete(IAsyncResult result) { if (result.CompletedSynchronously) { return; } InvokeAsyncResult invokeResult = result.AsyncState as InvokeAsyncResult; Fx.Assert(invokeResult != null, "Async state should have been of type InvokeAsyncResult."); try { invokeResult.durableInstance.EndFinishOperation(result); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } invokeResult.completionException = e; } invokeResult.Complete(false, invokeResult.completionException); }
public static object End(out object[] outputs, IAsyncResult result) { InvokeAsyncResult invokeResult = AsyncResult.End <InvokeAsyncResult>(result); outputs = invokeResult.outputs; return(invokeResult.returnValue); }
internal static InvokeResult EndInvokeMethodInternalWithResult(IAsyncResult asyncResult) { if (asyncResult == null) { throw new ArgumentNullException("asyncResult"); } InvokeAsyncResult r = (InvokeAsyncResult)asyncResult; if (!r.IsCompleted) { r.AsyncWaitHandle.WaitOne(); } if (r.ErrorCode != 0) { try { r.VM.ErrorHandler(null, new ErrorHandlerEventArgs() { ErrorCode = r.ErrorCode }); } catch (CommandException ex) { if (ex.ErrorCode == ErrorCode.INVALID_ARGUMENT) { throw new ArgumentException("Incorrect number or types of arguments", "arguments"); } throw; } throw new NotImplementedException(); } else { if (r.Exception != null) { throw new InvocationException((ObjectMirror)r.VM.DecodeValue(r.Exception)); } //refresh frames from thread after running an invoke r.Thread.GetFrames(); Value out_this = null; if (r.OutThis != null) { out_this = r.VM.DecodeValue(r.OutThis); } Value[] out_args = null; if (r.OutArgs != null) { out_args = r.VM.DecodeValues(r.OutArgs); } return(new InvokeResult() { Result = r.VM.DecodeValue(r.Value), OutThis = out_this, OutArgs = out_args }); } }
internal static void EndInvokeMultipleInternal(IAsyncResult asyncResult) { if (asyncResult == null) { throw new ArgumentNullException("asyncResult"); } InvokeAsyncResult r = (InvokeAsyncResult)asyncResult; if (!r.IsCompleted) { r.AsyncWaitHandle.WaitOne(); } }
internal static Value EndInvokeMethodInternal(IAsyncResult asyncResult) { if (asyncResult == null) { throw new ArgumentNullException("asyncResult"); } InvokeAsyncResult r = (InvokeAsyncResult)asyncResult; if (!r.IsCompleted) { r.AsyncWaitHandle.WaitOne(); } if (r.ErrorCode != 0) { try { r.VM.ErrorHandler(null, new ErrorHandlerEventArgs() { ErrorCode = r.ErrorCode }); } catch (CommandException ex) { if (ex.ErrorCode == ErrorCode.INVALID_ARGUMENT) { throw new ArgumentException("Incorrect number or types of arguments", "arguments"); } else { throw; } } throw new NotImplementedException(); } else { if (r.Exception != null) { throw new InvocationException((ObjectMirror)r.VM.DecodeValue(r.Exception)); } else { return(r.VM.DecodeValue(r.Value)); } } }
// This is called when the result of an invoke is received static void InvokeMultipleCB (ValueImpl v, ValueImpl exc, ValueImpl out_this, ValueImpl[] out_args, ErrorCode error, object state) { var r = (InvokeAsyncResult)state; Interlocked.Decrement (ref r.NumPending); if (r.NumPending == 0) { r.IsCompleted = true; ((ManualResetEvent)r.AsyncWaitHandle).Set (); } // Have to pass another asyncresult to the callback since multiple threads can execute it concurrently with results of multiple invocations var r2 = new InvokeAsyncResult { AsyncState = r.AsyncState, AsyncWaitHandle = null, VM = r.VM, Thread = r.Thread, Callback = r.Callback, IsCompleted = true }; if (error != 0) { r2.ErrorCode = error; } else { r2.Value = v; r2.Exception = exc; } r.Callback.BeginInvoke (r2, null, null); }
// // Implementation of InvokeMultiple // internal static IInvokeAsyncResult BeginInvokeMultiple (VirtualMachine vm, ThreadMirror thread, MethodMirror[] methods, Value this_obj, IList<IList<Value>> arguments, InvokeOptions options, AsyncCallback callback, object state) { if (thread == null) throw new ArgumentNullException ("thread"); if (methods == null) throw new ArgumentNullException ("methods"); foreach (var m in methods) if (m == null) throw new ArgumentNullException ("method"); if (arguments == null) { arguments = new List<IList<Value>> (); for (int i = 0; i < methods.Length; ++i) arguments.Add (new Value [0]); } else { // FIXME: Not needed for property evaluation throw new NotImplementedException (); } if (callback == null) throw new ArgumentException ("A callback argument is required for this method.", "callback"); InvokeFlags f = InvokeFlags.NONE; if ((options & InvokeOptions.DisableBreakpoints) != 0) f |= InvokeFlags.DISABLE_BREAKPOINTS; if ((options & InvokeOptions.SingleThreaded) != 0) f |= InvokeFlags.SINGLE_THREADED; InvokeAsyncResult r = new InvokeAsyncResult { AsyncState = state, AsyncWaitHandle = new ManualResetEvent (false), VM = vm, Thread = thread, Callback = callback, NumPending = methods.Length, IsMultiple = true }; var mids = new long [methods.Length]; for (int i = 0; i < methods.Length; ++i) mids [i] = methods [i].Id; var args = new List<ValueImpl[]> (); for (int i = 0; i < methods.Length; ++i) args.Add (vm.EncodeValues (arguments [i])); thread.InvalidateFrames (); r.ID = vm.conn.VM_BeginInvokeMethods (thread.Id, mids, this_obj != null ? vm.EncodeValue (this_obj) : vm.EncodeValue (vm.CreateValue (null)), args, f, InvokeMultipleCB, r); return r; }
internal static IInvokeAsyncResult BeginInvokeMethod (VirtualMachine vm, ThreadMirror thread, MethodMirror method, Value this_obj, IList<Value> arguments, InvokeOptions options, AsyncCallback callback, object state) { if (thread == null) throw new ArgumentNullException ("thread"); if (method == null) throw new ArgumentNullException ("method"); if (arguments == null) arguments = new Value [0]; InvokeFlags f = InvokeFlags.NONE; if ((options & InvokeOptions.DisableBreakpoints) != 0) f |= InvokeFlags.DISABLE_BREAKPOINTS; if ((options & InvokeOptions.SingleThreaded) != 0) f |= InvokeFlags.SINGLE_THREADED; if ((options & InvokeOptions.ReturnOutThis) != 0) f |= InvokeFlags.OUT_THIS; if ((options & InvokeOptions.ReturnOutArgs) != 0) f |= InvokeFlags.OUT_ARGS; InvokeAsyncResult r = new InvokeAsyncResult { AsyncState = state, AsyncWaitHandle = new ManualResetEvent (false), VM = vm, Thread = thread, Callback = callback }; thread.InvalidateFrames (); r.ID = vm.conn.VM_BeginInvokeMethod (thread.Id, method.Id, this_obj != null ? vm.EncodeValue (this_obj) : vm.EncodeValue (vm.CreateValue (null)), vm.EncodeValues (arguments), f, InvokeCB, r); return r; }
// // Implementation of InvokeMultiple // internal static IInvokeAsyncResult BeginInvokeMultiple(VirtualMachine vm, ThreadMirror thread, MethodMirror[] methods, Value this_obj, IList <IList <Value> > arguments, InvokeOptions options, AsyncCallback callback, object state) { if (thread == null) { throw new ArgumentNullException("thread"); } if (methods == null) { throw new ArgumentNullException("methods"); } foreach (var m in methods) { if (m == null) { throw new ArgumentNullException("method"); } } if (arguments == null) { arguments = new List <IList <Value> > (); for (int i = 0; i < methods.Length; ++i) { arguments.Add(new Value [0]); } } else { // FIXME: Not needed for property evaluation throw new NotImplementedException(); } if (callback == null) { throw new ArgumentException("A callback argument is required for this method.", "callback"); } InvokeFlags f = InvokeFlags.NONE; if ((options & InvokeOptions.DisableBreakpoints) != 0) { f |= InvokeFlags.DISABLE_BREAKPOINTS; } if ((options & InvokeOptions.SingleThreaded) != 0) { f |= InvokeFlags.SINGLE_THREADED; } InvokeAsyncResult r = new InvokeAsyncResult { AsyncState = state, AsyncWaitHandle = new ManualResetEvent(false), VM = vm, Thread = thread, Callback = callback, NumPending = methods.Length, IsMultiple = true }; var mids = new long [methods.Length]; for (int i = 0; i < methods.Length; ++i) { mids [i] = methods [i].Id; } var args = new List <ValueImpl[]> (); for (int i = 0; i < methods.Length; ++i) { args.Add(vm.EncodeValues(arguments [i])); } r.ID = vm.conn.VM_BeginInvokeMethods(thread.Id, mids, this_obj != null ? vm.EncodeValue(this_obj) : vm.EncodeValue(vm.CreateValue(null)), args, f, InvokeMultipleCB, r); return(r); }
public object InvokeEnd(object instance, out object[] outputs, IAsyncResult result) { return(InvokeAsyncResult.End(out outputs, result)); }
public IAsyncResult BeginInvoke(Delegate method, Object[] args) { lock( this.invokeEventQueue ) { InvokeParameters iParm = new InvokeParameters(); InvokeAsyncResult ar = new InvokeAsyncResult(); if( args != null ) { ar.AsyncState = args[args.Length - 1]; } iParm.method = method; iParm.args = args; iParm.wr = ar; if(toolkitWindow == null) { CreateControlInner(); } this.invokeEventQueue.Enqueue( iParm ); toolkitWindow.SendBeginInvoke(IntPtr.Zero); return ar; } }