title: Asynchronous memory streaming approach: which of the following?
body: <p>I am working on solution which uses asynchronous memory streaming and I am thinking about right approach for implementing such. Which one is more convenient? The first, simple:</p>
  
  <pre><code>//First approach: linear async
  private async static Task WriteToStreamFirstVariant()
  {
      MemoryStream memoryStream = new MemoryStream();
      byte[] data = new byte[256];
      try
      {
          await memoryStream.WriteAsync(data, 0, data.Length);
      }
      catch(Exception exception)
      {
          //Handling exception
      }
      finally
      {
          memoryStream.Dispose();
      }
  }
  </code></pre>
  
  <p>Or the second with nested tasks and closures?</p>
  
  <pre><code>//Second approach: nested tasks async
  private async static Task WriteToStreamSecondVariant()
  {
      await Task.Run(async () =&gt;
      {
          byte[] data = new byte[256];
          using (MemoryStream memoryStream = new MemoryStream())
          {
              await memoryStream.WriteAsync(data, 0, data.Length)
                  .ContinueWith((Task writingTask) =&gt;
                  {
                      //Handling exceptions
                      AggregateException exceptions = writingTask.Exception;
                  });
          }
      }); 
  }
  </code></pre>