Fix issue on .NET 4.0 where cancellation token is already disposed.

- Dispose the token only if it's not a result of ending an existing
  connection.
- Dispose the token before ending the connection.
- Catch ObjectDisposedException in SafeRegister's DisposableAction.