?
Solved

rotate proxies in C# thread

Posted on 2014-01-28
1
Medium Priority
?
581 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 40

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

741 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