I have a database with a large number of records. (Database value is updated through a webservice)
Each record / line type (ID, xmlfilename, operation, parameter, operation ID, status) means that the parameters of the operation specified by "parameter" With "xmlfilename" as specified in the 'xmlfile' operation as 'operation.' The part of the position is "intially" free as updated as reqd.
I want to use these (each line) operation threads .. The number of entries per 'id' per one thread. As long as there are 'id' rows in the DB bringing and "operation"
How can I do it efficiently with maximum equality and / or concurrency.
Is there any better way?
What is the best Threadpool or Custom Threads or ASIN programming?
Edit added: Here is the pseudo code that I tried
string operation id = zero; While (operationId = DBWorker.getNextFreeOperationId ()) // How do I check this? Another query? Unless the position is operated with "Free" /, select Operation / Note DB. Updating Asynchronous {// Operation Id = Get all the rows with Operation ID eg: 800 1 thread / qid ??? ? And // condition = "free" ... // There are several operations with the same operation IDS DataRowCollection dbRows = DBWorker.retrieveQueuedEntries (operationId); MyWorkItem workItem = New DBWorker.MyWorkItem (); WorkItem.DataRows = DBRO; WorkItem.Event = new AutoResetEvent (wrong); //MyWorkItem.DoWork will require "Operation" ThreadPool.QueueUserWorkItem (New WaitCallback (workItem.DoWork), workItem); } -------------- MyWorkItem.DoWork (obj x) {// Summary for each DataRow row in this. DataRows {performOperation (line); // Usage line ["Operation"] ..} --------------- Display Bool Operation (date line) {string operation = (string) row ["operation"]; // Recover the other similar switch (operation) {Add Case Operations: // Add call operation .. ...}} ------------
Using Code 2.2.0 .. does not receive multithreading .. The scenario may be that the database is updating asynchronously from one end, while the above code is running as a window service at the same time Will happen.
thx
Amit
If you do not use .NET 4.0 Use Threadpool - I'll create a function that will get the line (if you change the rows, it would be better to type correctly for typed objects), and what to do with it -
Using the system; Using System.Threading; Namespace SmallConsoleAppForTests {Class Program {Personal Static AutoResetEvent [] Events; Fixed zero main (string [] args) {int dataLength = 3; // Processing AutoResetEvent [] Events = New AutoResetEvent [dataLength] that has been made to create an array of AutoResetEvent; // Start the AutoResetEvent array in "no-set" values; For (int i = 0; i & lt; data lenthheth; i ++) events [i] = new autorsecurity (falls); // Processing for data (Int i = 0; i & lt; data length; i ++) {var data = new MyWareIT {event = events}, data = new MyDataClass ()}; Try ThreadPool.QueueUserWorkItem (x = & gt; {var dataItem = (MyWorkItem)}} {// Process on Data} {Exception E} {// Exception Handling} Finally {workItem.Event.Set ();} }, Data); } // Wait until all threads are finished. Wait. Wait (all); }} Public class MyWorkItem {public AutoResetEvent event {get; Set; } Public MyDataClass data {get; Set; If you are using .NET 4.0 - Check in Tasks and Parallel Extensions
You can also use DatRov for public class {// data // }}
/ P>
No comments:
Post a Comment