Running multiple threads
So I'm working on a link farmer, basicly it finds links that hold special items(hidden items that can be bought) by making an HttpWebRequest and reading the response stream.
I thought working with multiple threads might speed this up, since in theory having multiple threads searching is better than just one.
But apparently, it seems to slowdown the process.
Here's the code:
If you can figure out what's wrong with this, I'd be really appreciated.
I thought working with multiple threads might speed this up, since in theory having multiple threads searching is better than just one.
But apparently, it seems to slowdown the process.
Here's the code:
Code:
int t_count = GetSearchType(); //don't worry about this.
for (; t_count >= 0; t_count--)
new System.Threading.Thread(
() =>
{
for (Search_CurrentID += (int)IncrementNum.Value; Search_CurrentID < Search_MaxID && Running; Search_CurrentID += (int)IncrementNum.Value)
{
string link = link_mask + Search_CurrentID.ToString();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(link);
req.Timeout = 2000;
req.Method = WebRequestMethods.Http.Post;
req.ContentType = "application/x-www-form-urlencoded";
req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64_R3D) AppleWebKit/537.36 (KHTML, like Gecko) Safari/537.36";
req.ContentLength = 0;
using (StreamReader wStream = new StreamReader(req.GetResponse().GetResponseStream()))
{
for (string line = wStream.ReadLine(); !wStream.EndOfStream; line = wStream.ReadLine())
{
if (line.Contains("title story-title"))
{
Links_Searched++;
string title = line.Replace("<h1 class=\"title story-title\">", "").Replace("</h1>", "").Remove(0, " ".Length - 1);
loglink(link, title);
}
}
}
}
Running = false;
if (Search_CurrentID >= Search_MaxID && PopupOnCompleteCB.Checked)
notifyIcon.ShowBalloonTip(1000, "Aeria Link Farmer", "Search has been completed!", ToolTipIcon.Info);
}
).Start();
}
