Choosing Between WF CodeActivity and AsyncCodeActivity for DB Operations

浪尽此生 提交于 2019-12-13 13:21:28

问题


I'm still fairly new to WF so bear with me if I don't get this worded correctly the first time. ;)

If you're doing selects against a well-normalized database, using primary keys, returning single records, in a fairly low volume environment (a few hundred requests per day), does it really make a difference whether you use CodeActivity vs AsyncCodeActivity?

While I've got some additional research to do on hosting and execution, it will be possible, but not probable, for multiple requests to be received at or near the same time. I'm not sure if that will change the answer or not.

Thanks!


回答1:


Microsoft used non async in their ExecuteSqlQuery activity: http://wf.codeplex.com/releases/view/43585

Async Activities: "This is useful for custom activities that must perform asynchronous work without holding the workflow scheduler thread and blocking any activities that may be able to run in parallel."

"As a result of going asynchronous, an AsyncCodeActivity may induce an idle point during execution. Due to the volatile nature of asynchronous work, an AsyncCodeActivity always creates a no persist block for the duration of the activity’s execution. This prevents the workflow runtime from persisting the workflow instance in the middle of the asynchronous work, and also prevents the workflow instance from unloading while the asynchronous code is executing."

Source: http://msdn.microsoft.com/en-us/library/ee358731.aspx

Edit: I noticed that only pointed out the disadvantages of using async I would consider the responses of Ron and Tim to make a better decision




回答2:


In general I strongly encourage activity developers who are doing any kind of I/O to use AsyncCodeActivity and to call the underlying Async APIs whenever possible. Even if the query is short this is always preferrable.




回答3:


Obviously - it's not going to make a difference unless you're actually calling an Async API inside your activity implementation.

That said, even if it makes a difference it might not make a noticeable difference in many apps. Potential reasons:

  • The query just runs too fast.
  • You aren't running multiple queries in parallel. (Running many async operations in parallel is faster than doing them synchronously and thereby sequentially.)
  • You don't run a large number of workflows in parallel such as would be needed to experience thread contention.


来源:https://stackoverflow.com/questions/7418327/choosing-between-wf-codeactivity-and-asynccodeactivity-for-db-operations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!