private object RunAsyncTestMethod(TestExecutionContext context) { TLogger.Write("##### RunAsyncTestMethod in TTestMethodCommand class #####"); #region tronghieu.d - invoke async test method in application thread. This thread is blocked for waiting result. using (AsyncInvocationRegion region = AsyncInvocationRegion.Create(testMethod.Method.MethodInfo)) { TAsyncThreadMgr asyncThreadMgr = TAsyncThreadMgr.GetInstance(); asyncThreadMgr.SetData(this, testMethod, arguments, context, true); asyncThreadMgr.GetMethodExecutionResetEvent().Set(); // release main thread to invoke method _testMethodRunComplete.WaitOne(); // wait for result in current thread if (asyncThreadMgr.GetNonAsyncMethodException() != null) { throw asyncThreadMgr.GetNonAsyncMethodException(); } try { if (asyncThreadMgr.GetResult() == null) { return(asyncThreadMgr.GetResult()); } return(region.WaitForPendingOperationsToComplete(asyncThreadMgr.GetResult())); } catch (Exception e) { throw new NUnitException("Rethrown", e); } } #endregion }
private object RunNonAsyncTestMethod(TestExecutionContext context) { TLogger.Write("##### RunNonAsyncTestMethod in TTestMethodCommand class #####"); #region tronghieu.d - invoke async test method in application thread. This thread is blocked for waiting result. TAsyncThreadMgr asyncThreadMgr = TAsyncThreadMgr.GetInstance(); asyncThreadMgr.SetData(this, testMethod, arguments, context, false); asyncThreadMgr.GetMethodExecutionResetEvent().Set(); // release main thread to invoke method _testMethodRunComplete.WaitOne(); // wait for result in current thread if (asyncThreadMgr.GetNonAsyncMethodException() != null) { throw asyncThreadMgr.GetNonAsyncMethodException(); } return(asyncThreadMgr.GetResult()); #endregion //return testMethod.Method.Invoke(context.TestObject, arguments); }