We are running state machine workflow 3.5 on Asp.Net web application.
After upgrading the .Net framework from 3.5 to 4.6.1 we are getting serialization exception when calling instance.Unload()
I tried adding Thread.Sleep(1000) before Instance.Unload() and it worked
My question is how can I fix this problem without using Thread.Sleep(1000).
Note that we are initializing a new WorkflowRuntime in every time we use workflow
The root cause of the issue is we didn't specify the manual scheduler and kept the runtime use the default automatic scheduler which is using a different thread to handle the workflow.
Check the manual scheduler section in this article