title: How to set a timeout value on StreamSocket's ConnectAsync()?
body: <p>In the Windows Phone 8.1 app I had to create my socket as follows. How can I change it so that it will timeout after a period that I can specify?</p>
  
  <pre><code>_socket = new StreamSocket();
  await _socket.ConnectAsync(hostName, port.ToString(), SocketProtectionLevel.PlainSocket);
  
  await _socket.InputStream.ReadAsync(frameLenData, frameLenData.Capacity, Windows.Storage.Streams.InputStreamOptions.None);
  </code></pre>
  
  <p>In my pre- Windows Phone code I'd create the Socket and set the timeout by testing <code>_event.WaitOne(timeout)</code>, e.g.</p>
  
  <pre><code>timeout = 5000;
  _event = new ManualResetEvent(false);
  _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  
  bool bOperationFailed = false;
  SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
  socketEventArg.RemoteEndPoint = new DnsEndPoint(address, port);
  
  
  _event.Reset();
  
  _socket.ReceiveAsync(socketEventArg);
  
  // Wait for completion
  if (_event.WaitOne(timeout) == false)
  {
      Trace.trace("timed out");
      return false;
  }
  </code></pre>
  
  <p>Can I set the timeout period for <code>StreamSocket</code>'s <code>ConnectAsync()</code>? If so, how?</p>