{"id":2833,"date":"2019-11-11T15:51:23","date_gmt":"2019-11-11T14:51:23","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=2833"},"modified":"2022-07-25T08:33:24","modified_gmt":"2022-07-25T07:33:24","slug":"c-function-timeouts","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/c-function-timeouts\/","title":{"rendered":"C# Function Timeouts"},"content":{"rendered":"\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/\/ &lt;summary>\n\/\/\/ Limex: timout function. Usage:\n\/\/\/ &lt;\/summary>\n\/\/\/ &lt;typeparam name=\"T\">&lt;\/typeparam>\n\/\/\/ &lt;param name=\"F\">&lt;\/param>\n\/\/\/ &lt;param name=\"Timeout\">&lt;\/param>\n\/\/\/ &lt;param name=\"Completed\">&lt;\/param>\n\/\/\/ &lt;returns>&lt;\/returns>\npublic static T Limex&lt;T>(Func&lt;T> F, int Timeout, out bool Completed)\n{\n\tT result = default(T);\n\tThread thread = new Thread(() => result = F());\n\tthread.Start();\n\tCompleted = thread.Join(Timeout);\n\tif (!Completed) thread.Abort();\n\treturn result;\n}\n\n\/\/ Overloaded method, for cases when we don't\n\/\/ need to know if the method was terminated\npublic static T Limex&lt;T>(Func&lt;T> F, int Timeout)\n{\n\tbool Completed;\n\treturn Limex(F, Timeout, out Completed);\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[6,4,1],"tags":[],"class_list":["post-2833","post","type-post","status-publish","format-standard","hentry","category-dotnet","category-programming","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/2833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=2833"}],"version-history":[{"count":1,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/2833\/revisions"}],"predecessor-version":[{"id":2834,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/2833\/revisions\/2834"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=2833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=2833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=2833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}