{"id":1264,"date":"2014-02-05T20:19:13","date_gmt":"2014-02-05T20:19:13","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=1264"},"modified":"2014-02-05T20:19:13","modified_gmt":"2014-02-05T20:19:13","slug":"is-my-applications-ui-still-responsive","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/is-my-applications-ui-still-responsive\/","title":{"rendered":"Is my application&#8217;s UI still responsive ?"},"content":{"rendered":"<p>We might, on occasion, need to check whether an application we&#8217;ve spawned has a responsive UI or ofcourse we might wish to check our own application, for example within a timer polling the following code to check the application is still responsive.<\/p>\n<p>Firstly, we could use the property <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.diagnostics.process.responding.aspx\" title=\"Process.Responding Property\" target=\"_blank\">Responding<\/a> on the <em>Process<\/em> class which allows us to check whether a process&#8217;s UI is responsive. <\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nProcess p = Process.Start(&quot;SomeApplication.exe&quot;);\r\n\r\nif(!p.Responding)\r\n{\r\n   \/\/ the application's ui is not responding\r\n}\r\n\r\n\/\/ on the currently running application we might use \r\n\r\nif(!Process.GetCurrentProcess().Responding)\r\n{\r\n   \/\/ the application's ui is not responding\r\n}\r\n<\/pre>\n<p>Alternatively we could use the following code, which allows us to set a timeout value<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\npublic static class Responsive\r\n{\r\n   \/\/\/ &lt;summary&gt;\r\n   \/\/\/ Tests whether the object (passed via the ISynchronizeInvoke interface) \r\n   \/\/\/ is responding in a predetermined timescale (the timeout). \r\n   \/\/\/ &lt;\/summary&gt;\r\n   \/\/\/ &lt;param name=&quot;si&quot;&gt;An object that supports ISynchronizeInvoke such \r\n   \/\/\/ as a control or form&lt;\/param&gt;\r\n   \/\/\/ &lt;param name=&quot;timeout&quot;&gt;The timeout in milliseconds to wait for a response \r\n   \/\/\/ from the UI&lt;\/param&gt;\r\n   \/\/\/ &lt;returns&gt;True if the UI is responding within the timeout else false.&lt;\/returns&gt;\r\n   public static bool Test(ISynchronizeInvoke si, int timeout)\r\n   {\r\n      if (si == null)\r\n      {\r\n         return false;\r\n      }\r\n      ManualResetEvent ev = new ManualResetEvent(false);\r\n      si.BeginInvoke((Action)(() =&gt; ev.Set()), null);\r\n      return ev.WaitOne(timeout,false);\r\n   }\r\n}\r\n<\/pre>\n<p>In usage we might write the following<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nif (IsHandleCreated)\r\n{\r\n   if (!Responsive.Test(this, reponseTestDelay))\r\n   {\r\n       \/\/ the application's ui is not responding\r\n   }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We might, on occasion, need to check whether an application we&#8217;ve spawned has a responsive UI or ofcourse we might wish to check our own application, for example within a timer polling the following code to check the application is still responsive. Firstly, we could use the property Responding on the Process class which allows [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,53],"tags":[],"class_list":["post-1264","post","type-post","status-publish","format-standard","hentry","category-c","category-windows"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/1264","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=1264"}],"version-history":[{"count":7,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/1264\/revisions"}],"predecessor-version":[{"id":1287,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/1264\/revisions\/1287"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=1264"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=1264"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=1264"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}