{"id":25,"date":"2008-04-06T11:50:00","date_gmt":"2008-04-06T11:50:00","guid":{"rendered":"http:\/\/localhost:10265\/?p=24"},"modified":"2008-04-06T11:50:00","modified_gmt":"2008-04-06T11:50:00","slug":"the-c-counterpart-of-mfcs-cwaitcursor","status":"publish","type":"post","link":"https:\/\/mehdi.biz\/blog\/2008\/04\/06\/the-c-counterpart-of-mfcs-cwaitcursor\/","title":{"rendered":"The C# counterpart of MFC&#8217;s CWaitCursor"},"content":{"rendered":"<!-- google_ad_section_start --><p>Hi,<br \/>\nFor those who are not familiar with MFC, the CWaitCursor class provides a way to show a wait cursor, which is usually displayed as an hourglass, while you&#8217;re doing a lengthy operation. There are plenty of ways to modify the pointing device&#8217;s cursor under C#, however, the one I&#8217;m going to bring up here is simple and straight forward that has been used over the past years for my programs.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nusing System;\nusing System.Threading;\nusing System.Windows.Forms;\n\n\/\/\/ &lt;summary&gt;\n\/\/\/ Provides a utility class to handle the pointing device's wait cursor.\n\/\/\/ &lt;\/summary&gt;\npublic class WaitCursor : IDisposable\n{\n    private static int refCount = 0;\n\n    \/\/\/ &lt;summary&gt;\n    \/\/\/ Initializes a new instance of the WaitCursor class.\n    \/\/\/ &lt;\/summary&gt;\n    public WaitCursor()\n    {\n        Interlocked.Increment(ref refCount);\n        Cursor.Current = Cursors.WaitCursor;\n    }\n\n    \/\/\/ &lt;summary&gt;\n    \/\/\/ Sets the default cursor.\n    \/\/\/ &lt;\/summary&gt;\n    public void Dispose()\n    {\n        if (Interlocked.Decrement(ref refCount) == 0)\n            Cursor.Current = Cursors.Default;\n    }\n}\n<\/pre>\n<p>Finally, to use the WaitCursor class, you just do the following:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nusing (new WaitCursor())\n{\n    \/\/Do a lengthy operation\n}\n<\/pre>\n<p>That&#8217;s all for now, folks!<\/p>\n<!-- google_ad_section_end -->","protected":false},"excerpt":{"rendered":"<p>Hi,<br \/> For those who are not familiar with MFC, the CWaitCursor class provides a way to show a wait cursor, which is usually displayed as an hourglass, while you&#8217;re doing a lengthy operation. There are plenty of ways to modify the pointing device&#8217;s cursor under C#, however, the one I&#8217;m going to bring up [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-csharp"],"_links":{"self":[{"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/comments?post=25"}],"version-history":[{"count":0,"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/posts\/25\/revisions"}],"wp:attachment":[{"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/media?parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/categories?post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mehdi.biz\/blog\/wp-json\/wp\/v2\/tags?post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}