public void TestForceCancel() { // same as cancel, call it several times should be ok // call cancel, several times, we should not crash AutoResetEvent cancelled = new AutoResetEvent(false); connection.SetStateChangeHandler((s, e) => { switch (s) { case NWConnectionState.Cancelled: cancelled.Set(); break; } }); connection.ForceCancel(); Assert.IsTrue(cancelled.WaitOne(3000), "Cancelled"); connection.ForceCancel(); // lib should ignore the second call Assert.IsFalse(cancelled.WaitOne(3000)); }