title: Async / Await Lambdas
body: <p>I have a strange problem combining the async/await to make it work:
  I created a small procedure, which should handle basically the try/catch of every action:</p>
  
  <pre><code>    internal static void HandledAction(Action action, Info infoBar)
      {
          try
          {
              action();
          }
          catch (Exception ex)
          {
              infoBar.SetError("An Exception occured: " + ex.Message);
              WriteLog(ex.StackTrace);
          }
  </code></pre>
  
  <p>Nohing to fancy, but it's worth since changing error-handling is very easy made.
  But what happens, if I'd like to get Data async in the Lambda? Lets take this simple example:</p>
  
  <pre><code>    private void mnuImportData_Click(object sender, RoutedEventArgs e)
      {
          ActionHelper.HandledAction(async () =&gt;
          {
              throw new NotImplementedException("Ups");
          }, infoMain);
      }
  </code></pre>
  
  <p>Sure, the HandledAction gets called, passes, since it gets the pointer back, and the exception gets thrown, of course not handled.</p>
  
  <p>I imagine I have to create a AsyncHandledAction, and set the action async, but is there a easier way to solve this problem?</p>
  
  <p>I guess many people use a central exception-handling, and there are far better solutions for this?</p>
  
  <p>Thanks in advance</p>
  
  <p>Matthias</p>
  
  <p>Edit: I created an example, which should shpw netter I need: I basically dont want the whole Action I pass being awaitable, but one call in the Lambda is:</p>
  
  <pre><code>ActionHelper.HandledActionAsync(() =&gt;
          {
              //elided
              CheckFileResult rslt = await excelImport.CheckFilesAsync(tmpPath);
              //elided
          }, infoMain);
  </code></pre>
  
  <p>Of course, by doing so, I get the error: </p>
  
  <p>Error   3   The 'await' operator can only be used within an async lambda expression. Consider marking this lambda expression with the 'async' modifier.</p>