title: How to handle exception in a background thread in a unit test?
body: <p>I'm writing a unit test suite to test a TCP/IP communication library.</p>
  
  <p>As I'm using BeginAcceptClient and EndAcceptClient, the messages are received in a background thread.</p>
  
  <p>After a message is received, I perform some assertions on it, but if any assertion fails, the VSTestHost.exe crashes.</p>
  
  <p>I googled a bit and found out its the fact the Assert exceptions are being thrown in a background thread.</p>
  
  <p>EDIT: A sample code of what I am doing, just to ilustrate:</p>
  
  <pre><code>
  public void TestFooMessage() {
      Server.OnReceive += (s, e) => {
          Assert.IsInstanceOfType(e.Message, typeof(Foo));
      };
  
      var message = new Foo();
      Client.Send(message);
  }
  </code></pre>
  
  <p>Does anyone know how to make it work as expected: Log the assertion and continues running normally?</p>