void IAsyncProfileTestFixture.Begin(IAsyncTestResult result, MethodInfo beginMethod, MethodInfo endMethod) { // Store the end method and invoke the begin right now. _endMethod = endMethod; beginMethod.Invoke(this, null); // Everything should now be set up. BeginSend(result); }
private void End(IAsyncTestResult result, bool completedSynchronously) { try { // Give the test case a chance to check the response. _endMethod.Invoke(this, null); // Mark it as complete. result.SetComplete(completedSynchronously); } catch (Exception ex) { result.SetComplete(ex, completedSynchronously); } }
private void BeginSend(IAsyncTestResult result) { Prepare(); // Create the request. var request = _isGet ? CreateGetRequest() : CreatePostRequest(); // Set up RequestState. var state = new RequestState { Request = request, Result = result }; // Send it. var timer = GetTimer(); timer.Start(); var innerResult = _client.BeginSend(request, ResponseCallback, state); // Check whether it has already been done. if (innerResult.CompletedSynchronously) { timer.Stop(); var response = (HttpWebResponse)request.GetResponse(); var content = _client.ReadResponse(response, response.GetResponseStream()); // End it. Process(content); End(result, true); } else { // Register timeout callback. ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, ResponseTimeoutCallback, state, 60000, true); } }