Solved

rotate proxies in C# thread

Posted on 2014-01-28
1
515 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 39

Accepted Solution

by:
Kyle Abrahams earned 500 total points
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now