Solved

rotate proxies in C# thread

Posted on 2014-01-28
1
555 Views
Last Modified: 2014-01-29
I'm using the following code to multithread a c# datatable.


Spider spd = new Spider(i, doneEvents[i]);
spiderArray[i] = spd;
ThreadPool.QueueUserWorkItem(spd.RunSpider, myTempThreadTable);

Open in new window


How to I rotate within the threads a proxy DataTable table that is shared by the threads?
Where would I place the code?
0
Comment
Question by:esak2000
1 Comment
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 39817887
I've never been a big fan of the thread pool.

If you're willing to redesign a little bit here's how I did something similiar:

1:  As your spawning each thread, create a thread id so that you have a unique identifier for each thread.

2:  Add a column to your datatable called threadID set it to 0 initially.

3:  When you're ready to grab the proxy - lock the datatable.  Set the first row's threadid to the id of the thread that is running where threadid = 0, then unlock.

4:  Continue as normal.

5:  When done with that row, Lock the datatable.  You can update the datatable to set threadid to -1.  

If you need to loop over these again and again, update the table to set all rows to 0 where threadid = -1 when (select count(*) from datatable where threadid = 0) = 0. . . this will ensure you don't overwrite the threads that still have a lock on that row.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question