Adding handler to DatagramSocket.MessageReceived results in exception

Answered Adding handler to DatagramSocket.MessageReceived results in exception

  • Sunday, September 18, 2011 3:22 PM
     
      Has Code
    While experimenting with the new Sockets API I have encountered an error. The following is simplified simple code snippet I used:
     
    DatagramSocket socket = new DatagramSocket();
    await socket.ConnectAsync("208.67.222.222", "53");
    var tcs = new TaskCompletionSource<DatagramSocketMessageReceivedEventArgs>();
    socket.MessageReceived += (sender, e) => tcs.SetResult(e);
    
    Now the last line that adds MessageReceived event handler throws a COMException with the helpful text "Unspecified error". Am I doing something wrong or is it possibly a bug (in documentation or my code)?

All Replies

  • Sunday, September 18, 2011 10:15 PM
     
     Answered
    Apparently it seems to work fine if MessageReceived event handler is registered before calling ConnectAsync, so it's most probably just a documentation problem.