{"id":22,"date":"2005-05-10T22:47:36","date_gmt":"2005-05-11T05:47:36","guid":{"rendered":"http:\/\/kennyw.com\/indigo\/22"},"modified":"2005-05-10T22:47:36","modified_gmt":"2005-05-11T05:47:36","slug":"channels-102b-close-vs-abort-vs-dispose","status":"publish","type":"post","link":"https:\/\/kennyw.com\/?p=22","title":{"rendered":"Channels 102b: Close vs. Abort (vs. Dispose)"},"content":{"rendered":"<p>A major source of confusion with Indigo Beta 1 is how to shut down our communication objects, so I&#8217;m going to drill further into this topic.   First, I must note that this area is under review for Beta 2.  We understand there are some inconsistencies between our usage of <code>IDisposable<\/code> and its usage by other parts of the .Net Framework.  But the CTP bits are what you have to work with for now, so I will do my best to explain them \ud83d\ude42<\/p>\n<p>When I talked about the <a href=\"http:\/\/kennyw.com\/indigo\/18\">common state machine<\/a> in Indigo, I neglected to point out that <code><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.servicemodel.icommunicationobject.aspx\">ICommunicationObject<\/a><\/code> derives from <code><a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpref\/html\/frlrfsystemidisposableclasstopic.asp\">IDisposable<\/a><\/code>.   This gives you a third option (in addition to our Close() and Abort() methods) for shutdown. It also allows you to use any ICommunicationObject with the C# <code class=\"keyword\">using<\/code> statement.<\/p>\n<p>In the CTP bits, Dispose == Abort.  Or put another way, Dispose != Close.   This is a point worth re-iterating.  Dispose will rudely abort your object.<\/p>\n<p>So when you are done with an ICommunicationObject, what should you do?<\/p>\n<p>First you should call Close(), which will flush any outstanding buffers, acknowledge outstanding data, and provide a graceful shutdown.  This is similar to what happens when you call Stream.Close() or XmlWriter.Close().  Then you should make sure that Abort\/Dispose is called if anything fails (i.e. throws an exception).  This way any heavyweight network resources are released in an eager fashion.<\/p>\n<p>Which leads to code like the following:<\/p>\n<div class=\"code\">\n<div class=\"indent1\">\nIOutputChannel channel = CreateOutputChannel();<\/p>\n<p><code class=\"keyword\">using<\/code> (channel)<br \/>\n{<\/p>\n<div class=\"indent1\">channel.Open();<br \/>\nchannel.Send(message);<br \/>\nchannel.Close();<\/div>\n<p>}<\/p><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>A major source of confusion with Indigo Beta 1 is how to shut down our communication objects, so I&#8217;m going to drill further into this topic. First, I must note that this area is under review for Beta 2. We understand there are some inconsistencies between our usage of IDisposable and its usage by other [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[26,80,85,91],"class_list":["post-22","post","type-post","status-publish","format-standard","hentry","category-indigo","tag-channel","tag-transports","tag-wcf","tag-work"],"_links":{"self":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts\/22","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=22"}],"version-history":[{"count":0,"href":"https:\/\/kennyw.com\/index.php?rest_route=\/wp\/v2\/posts\/22\/revisions"}],"wp:attachment":[{"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kennyw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}