[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

rotate proxies in C# thread

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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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!
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

650 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