Project Name File Name Usage Source Code Link
AwsSesWrapper.Net CommandProcessor.cs Task.Factory.StartNew( () => { //Exception exception = null; byte[] responseData = null; Task getRequestStreamTask = Task.Factory.FromAsync(request.BeginGetRequestStream, request.EndGetRequestStream, null) .ContinueWith(task => { if (task.Exception != null) { // usually DNS issue or server unresponsive //exception = task.Exception; throw task.Exception; //return; } // write data to request stream Stream outStream = task.Result; byte[] data = dataGetter(); if (data == null || data.Length == 0) { return; } Task writterTask = Task.Factory.FromAsync(outStream.BeginWrite, outStream.EndWrite, data, 0, data.Length, outStream, TaskCreationOptions.AttachedToParent) .ContinueWith( x => ((Stream) x.AsyncState).Close()); writterTask.Wait(); }); getRequestStreamTask.Wait(); //if(exception != null) //{ // return null; //} // get response Task requestTask = Task.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse, null, TaskCreationOptions.AttachedToParent) .ContinueWith(task => { //HttpWebResponse response = null; if (task.Exception != null) { //exception = task.Exception; if (task.Exception.InnerException is WebException) { var webException = (WebException)task.Exception.InnerException; var response = webException.Response as HttpWebResponse; if (response != null && response.StatusCode != HttpStatusCode.OK) { //responseData = GetData(response); var error = new ErrorResponseParser().Process(response.GetResponseStream()); throw new AwsSesException(error, task.Exception.InnerException); } } throw task.Exception; } responseData = GetData(task.Result); } ); requestTask.Wait(); return responseData; }, TaskCreationOptions.AttachedToParent) Link To Source File