开发者

How to FORCEFULLY kill a WorkflowInstance?

开发者 https://www.devze.com 2023-03-17 05:32 出处:网络
I have a somewhat unusual scenario where I need to be able to outright slaughter \"hung\", self-hosted WorkflowInstance\'s after a given timeout threshold.I tried the Abort(), Terminate() and Cancel()

I have a somewhat unusual scenario where I need to be able to outright slaughter "hung", self-hosted WorkflowInstance's after a given timeout threshold. I tried the Abort(), Terminate() and Cancel() methods but these are all too "nice". They all appear to require a response from the WorkflowInstance before they are honored.

In my scenario, a workflow entered an infinite loop and was therefore unresponsive. Calls to the normal methods mentioned above would simply hang since the workflow was completely unresponsive. I was surprised to learn the WorkflowRuntime does not appear have a mechanism for dealing with this scenario, or that Abort() and Terminate() are merely suggestions as opposed to violent directives.

I scoured google/msdn/stackoverflow/etc trying to find out what to do when Terminate() simply isn't going to get the job done and came up dry. I considered creating my own base activity and giving it a timeout value so my "root" activity can k开发者_开发技巧ill itself if one of its child activities hangs. This approach seems like I'd be swatting at flies with a sledge hammer...

Is there a technique I overlooked?


The only true solution is to consider this a bug, fix whatever went wrong, and consider the matter closed.

The only way to forcibly abort any code that is locked in an infinite loop is to call Abort() on the thread. Of course, this is considered bad juju, and should only be done when the state of the application can be ensured after the call.

So, you must supply the WorkflowApplication an implementation of SynchronizationContext that you write which can call Abort() on the thread that the workflow Post()s to.


I am not sure if this will work, but have you tried the WorkflowInstance.TryUnload() function? I remember this to fire off a few events inside of the workflow (been a while since I did this), so you might be able to have an event handler in your workflow that catches this and does a kill switch on itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号