-
June 9th, 2011, 12:10 PM
#1
Multithreading DotNet4 & VB2010
Hey guys,
And so I decided to make a multithreaded application :'(
I am new to multiple threads - so my problem is this...
4 Threads
1 Array of lets say 100 strings
How do I make the 4 threads access the same array - also, once one string has been used(read) - it will be removed by a function that I have written already.
So the problem I'm experiencing is that when the 1st thread removes the string from the array at that specific stage the 3rd might be accessing the array and the string returned from the array = nothing...
Any ideas?
-
June 9th, 2011, 12:50 PM
#2
Re: Multithreading DotNet4 & VB2010
This is a Loaded Question..
so before answering, a few questions...
#1: what sort of processing are you doing on this array of strings?
#2: How long does this processing take per iteration?
#3: How CPU intensive is this processing ?
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
June 9th, 2011, 01:56 PM
#3
Re: Multithreading DotNet4 & VB2010
Right - thank you for pointing out those points
The array is used as a hyperlink collector - I'm writing a kind of spider for research and what needs to be done is as follow.
The array contains hyperlinks, it needs to be sorted which is easy through Array.Sort(Array)
Then the douples needs to be removed - also easy by using Array.BinarySearch(Array, Value)
Then removing the entry, I have written a function to do that.
So now the problem - testing the link and removing it when there is success and inserting it to another array.
This is where the multiple threads come in.
Processing time depends on response time.
Not so much CPU intensive, if list was larger yes... Not at the moment.
-
June 9th, 2011, 04:31 PM
#4
Re: Multithreading DotNet4 & VB2010
Spiders are not Well Liked.... And Many webmasters(Like myself) Block Spider IP's & agents..
SO .. I'll Ask you not to post any of the spider code.. However with the Array i'll help you...
Note: This is Few of many ways to solve..
#1 : Split the Array into 4 (Thread 1 works with 1-25, #2 with 26-50, etc)
#2 : Create a second Boolean array to mirror the first... loop through the Array, testing the Matching Bool and if False, set to true and process this one...
#3 : Use Prefixing on the strings to mark processed strings .. Web address starts with 'HTTP' so prefixing with a number or such can work (testing for this is easy)..
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
-
June 10th, 2011, 01:22 AM
#5
Re: Multithreading DotNet4 & VB2010
Hehe, ye I can understand why you do that
So no spider code here
I did think of splitting the array into four - though the coding complexity increases.
The second bool array is an idea - will try it for a test.
The prefix idea - almost the same as the bool idea, but at least one array less... Also will try
Thanks for the ideas - it was staring me right in the face -=facepalm=-
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|