Hi guys,
i have database with larger number of records.(database values are updated via a webservice)
Each record/row is of type (id,xmlfilename,operation,parameters,operationId,status) ie. we have perform operation as specified by'operation' on a xmlfile specified by "xmlfilename" with parameters for operation specified by "parameters".. status part is "intially" free as is updated as when reqd.
I have to do these (each row) operation using Threads..ie one thread per 'id' number of entries.as long as there are 'id' rows in db fetch and perform "operation"
how can i do this efficiently with maximum parallelism and/or concurrency.
Is there a better way?
What is best suited Threadpool or custom threads or asyn programming?
Edit Added:Here is pseudo code i tried
string operationId=null;
while(operationId = DBWorker.getNextFreeOperationId ())
//how do i check this?another query??untill there are operations with status "Free"
//,keep selecting operationids
//note db is updating asynchronously.
{
//retrieve all rows with operationid=operationId eg:800 . 1 thread/qid???? and
// status="free" ...
//there are multiple operations with same operationIds
DataRowCollection dbRows=DBWorker.retrieveQueuedEntries(operationId);
MyWorkItem workItem = new DBWorker.MyWorkItem();
workItem.DataRows = dbRows;
workItem.Event = new AutoResetEvent(false);
//MyWorkItem.DoWork will do the necessary "Operation"
ThreadPool.QueueUserWorkItem(new WaitCallback(workItem.DoWork),workItem);
}
--------------
MyWorkItem.DoWork(obj x){
//for brevity
for each DataRow row in this.DataRows
{
performOperation(row);//use row["operation"] ..
}
---------------
bool performOperation(DataRow row)
{
string operation = (string)row["operation"];//retrieve other similarly
switch(operation)
{
case Operations.Add: //call Add operation ..
...
}
}
------------
above code is using.net2.0.. doesnt achieve multithreading .. scenario may be the database is updating from one end asynchronously,while above code will be running as windows service at the same time.
thx
Amit