i have following code in c#:
private application getapplication() { application application = null; thread thread = new thread(() => { try { application = application.getactiveinstance(); } catch (exception exception) { application = null; } }); thread.start(); if (!thread.join(timespan.fromseconds(3))) { thread.abort(); return null; } return application; }
sometimes, when line of code runs thread hangs:
application = application.getactiveinstance();
in initial implementation didn't have thread in method, after noticed hang tried add in thread timeout can abort if hangs , return null application not freeze.
however when timeout occurs , thread.abort() method called thread not aborted , application.getactiveinstance() method continues hang.
and here magic:
the application.getactiveinstance() method thirty-party library handles word processes , tries current active process. method works successfully. when zombie word process exists in task manager method hangs. case want avoid.
how can force abort in thread when timeout occurs?
also, when terminate zombie word process task manager code runs:
catch (exception exception) { application = null; }
and exception abortexception thread.
how can kill thread immediately?
please, help.