Asynchronous CommandBase?

Asynchronous CommandBase?

Old forum URL: forums.lhotka.net/forums/t/2273.aspx


DogSpots posted on Sunday, February 04, 2007

I need to be able to start a lengthy procedure whenever a certain business object is saved.  The lengthy procedure takes quite a long time, and it does not change the object that started it, but it does get, update and save many other business objects.  The UI does not need to know when the lengthy process is done.  In fact, the UI doesn't even need to know that the process was started. 

I tried creating a CommandBase object, but I don't know how to get the CommandBase object to return before it is actually done.  I'm considering a BackgroundWorker, but I'm not sure if that is safe.

I'm working with a RemotingHost DataPortal and would like the lengthy process to run on the DataPortal.

Any ideas?

William replied on Sunday, February 04, 2007

I would suggest to push your lengthy processing request into a queue (for example, MSMQ) and the back-end job picks it up to complete the processing.
 
Regards,
William

McManus replied on Monday, February 05, 2007

Bill,

Why not start the lengthy procedure from within the DataPortal_xyz method? You are already on the server side when that method runs. Just start the procedure asynchronously on another thread. The DataPortal_xyz wouldn't have to wait for it.

Hope this helps!

Cheers,

Herman

RockfordLhotka replied on Monday, February 05, 2007

I agree with these comments. I would suggest that your DataPortal_Execute() method be used to put data into the database, then place an item in a queue of some sort.

Obviously this means you'll have a queue listener, that activates when items are in the queue and processes them. The actual work would occur in this queue listener process on the server.

You can use raw MSMQ (System.Messaging), COM+ Queued Components (which is MSMQ, but with automatic retry processing if the task fails), the Service Broker in SQL Server or roll your own using a Windows Service and a SQL table.

If you want to be really fancy, you could use .NET 3.0's Windows Workflow Foundation (WF) to implement your processing. The queue listener, in this case, would merely kick off a workflow, which would do the actual work Big Smile [:D]

Copyright (c) Marimer LLC