Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choosing Between WF CodeActivity and AsyncCodeActivity for DB Operations

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!

like image 976
John Laffoon Avatar asked Dec 22 '22 08:12

John Laffoon


2 Answers

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

like image 146
Davi Fiamenghi Avatar answered Dec 24 '22 00:12

Davi Fiamenghi


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.

like image 31
Ron Jacobs Avatar answered Dec 24 '22 01:12

Ron Jacobs