title: C# 5 async / await simplistic explanation
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/13082074/brief-explanation-of-async-await-in-net-4-5">Brief explanation of Async/Await in .Net 4.5</a>  </p>
  </blockquote>
  
  
  
  <p>I've been programming in C# for a while now, but I can't get my head around how the new <strong>async</strong> / <strong>await</strong> language feature works.</p>
  
  <p>I wrote a function like this:</p>
  
  <pre><code>public async Task&lt;SocketError&gt; ConnectAsync() {
      if (tcpClient == null) CreateTCPClient();
      if (tcpClient.Connected)
          throw new InvalidOperationException("Can not connect client: IRCConnection already established!");
  
      try {
          Task connectionResult = tcpClient.ConnectAsync(Config.Hostname, Config.Port);
          await connectionResult;
      }
      catch (SocketException ex) {
          return ex.SocketErrorCode;
      }
  
      return SocketError.Success;
  }
  </code></pre>
  
  <p>But clearly, there's no point to this, right? Because I'm awaiting the result of TcpClient.ConnectAsync on the line immediately after.</p>
  
  <p>But I wanted to write my <strong>ConnectAsync()</strong> function so that it itself could be awaited in another method. Is this the right approach? I'm a bit lost. :)</p>