[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

rotate proxies in C# thread

Posted on 2014-01-28
1
Medium Priority
?
605 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 41

Accepted Solution

by:
Kyle Abrahams earned 2000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Loops Section Overview
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month18 days, 2 hours left to enroll

831 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