Partager via


What's the Difference Between Close and Abort?

It's not uncommon to hear people wonder how calling Abort() is different from calling Close().  The purpose of Close is to request that an object go through a graceful shutdown process.  The purpose of Abort is to demand that an object have an immediate and painful death.  Here are six differences that I can think of for everyone that uses our implementation of CommunicationObject.

  1. A normal close sequence calls OnClosing, OnClose, and OnClosed.  A normal abort sequence calls OnClosing, OnAbort, and OnClosed.
  2. Calling Close with no arguments is the same as calling Close with some default timeout.  Abort never takes a timeout.  This means that the code that gets run while aborting must not block.
  3. Calling Close when in the Opened state closes normally and calling Close when in the Closing state does nothing.  Calling Abort in either the Opened or Closing states aborts normally.  Calling Close is the same as calling Abort when in the Created, Opening, Faulted, and Closed states.
  4. Calling Close traces if you've enabled tracing open and close events.  Calling Abort traces if this is the first time you've aborted the object and you're not in the Closed state.
  5. If you throw an exception while closing, the object gets aborted.  If you throw an exception while aborting, we just stop processing and let the exception escape.
  6. Abort doesn't care if you're in a bogus state.  Close will terminate the process.

Can you think of any more differences you've encountered?

Next time: How Internet Addresses Work

Comments

  • Anonymous
    March 23, 2006
    Continuing from yesterday's article about IChannelFactory, today we're looking at the server side of...