By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,693 Members | 1,564 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,693 IT Pros & Developers. It's quick & easy.

How to thread a function as array (or better)

P: n/a
Hi NG,
first of all sry about my english :) maybe it's somethin' funny to you

Following situation:

I've a structure like this:

Structure _Test
Dim IP as String
Dim UserLogin as String
End Structure
Dim Test() as _Test

This should keep the given information in an array, where each array-item is
used for one ip in local network.

In the main code the structure goes initialized like this:

Redim Test(2)
Test(0) = New _Test
Test(1) = New _Test
Test(2) = New _Test
Test(0).IP = "192.168.0.1"
Test(1).IP = "192.168.0.10"
Test(2).IP = "192.168.0.100"

Now I'll move my structure through a function.

Test = ProcessStruct(Test)

This structure does the following:
It calls for each item another function, witch is processing the ip and gets
back the Username. This is written in the structure. On End the actualized
structure is returning.

And all works fine, but:
When I want to scan the complete subnet-range (ie 192.168.0.x) it could hang
my program up to 4sec per ip, when function gets timeout.
Now I want to use threads, but I've no idea how to passing the structure
through the thread.
I think it must be possible, that the main function calls the 2nd function
(witch retrive information) all 100ms (for example) with the next ip. The
main function should gets the returned information and assemble it to the
structure.
But how to do it? I tried with events, but withevents wont work with arrays.
Now I'm confused and need help or other examples, how to do it better, than
I thougt.

Thanks and please help!
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
You should be able to put your thread sub in the same class or module and it
will have access to your test array. If you are going to access your array
in your class while the threaded sub is running, you will want to use
SyncLock on the code that modifies the test array.

"TommyB" wrote:
Hi NG,
first of all sry about my english :) maybe it's somethin' funny to you

Following situation:

I've a structure like this:

Structure _Test
Dim IP as String
Dim UserLogin as String
End Structure
Dim Test() as _Test

This should keep the given information in an array, where each array-item is
used for one ip in local network.

In the main code the structure goes initialized like this:

Redim Test(2)
Test(0) = New _Test
Test(1) = New _Test
Test(2) = New _Test
Test(0).IP = "192.168.0.1"
Test(1).IP = "192.168.0.10"
Test(2).IP = "192.168.0.100"

Now I'll move my structure through a function.

Test = ProcessStruct(Test)

This structure does the following:
It calls for each item another function, witch is processing the ip and gets
back the Username. This is written in the structure. On End the actualized
structure is returning.

And all works fine, but:
When I want to scan the complete subnet-range (ie 192.168.0.x) it could hang
my program up to 4sec per ip, when function gets timeout.
Now I want to use threads, but I've no idea how to passing the structure
through the thread.
I think it must be possible, that the main function calls the 2nd function
(witch retrive information) all 100ms (for example) with the next ip. The
main function should gets the returned information and assemble it to the
structure.
But how to do it? I tried with events, but withevents wont work with arrays.
Now I'm confused and need help or other examples, how to do it better, than
I thougt.

Thanks and please help!

Nov 21 '05 #2

P: n/a
TommyB,

What do you think that the result from a thread will be.

I know at least one, It will take some more time to get the IP address.

However when you want to test them all together in the same logical time,
than you can gain some performance when this is a kind of ping operation.

Use than a Queue wherin you have your structures.

Here in this message is a little sample of that from me with two assynchroon
working threads which give back the results.

http://groups-beta.google.com/group/...a15afdb6?hl=en

I hope this helps,

Cor
Nov 21 '05 #3

P: n/a
Many thanks for that!
Well, I think my question wasn't very good formed, sorry for that.
I know, if I call all requests at one time, they'll wont work as they're
developed for and could hanging my System.
Well, I don't want to run all threads like this. I thougt before it's
possible to create an array of threads with a bound from 0 to 9 (10 threads)
witch are calling the same function. This threads should started like this:

Do While RequestsRemaining > 0
For intCnt = 0 to 9
If tWorker(intCnt).State <> Running Then ' Start the Thread only
if previous process is finish (not in Syntax)
tWorker(intCnt).??? = ??? ' Gives the thread the IP, that
should be processed in it
tWorker(intCnt).Start ' Starts the thread
Thread.Sleep(100) ' Hold this thread für
100ms. Should be enough for sending the request
' without
waiting for the answer
End If
Next
Loop
' Jump out if all Requests are send
RaiseEvent CollectDataFinished

True, not coded out, because I don't know how, but for visualation it should
be enough.
Fill the Threads with the Row-Number of the structure and start for
processing it, if it's not already running.
Run with a maximum of 10 open requests at one time and each new process
should keep the next thread 100ms to wait for. This should be enough to send
the Request to the Client. If an answer goes back to the thread (real answer
or timeout-message), it'll put the data to the given row on the structure
and raise an event, so the main code can see, there are changes.
Well, I try now to understand your code and use it to help me out. It's
clearly typed, but I had never before seen the 'Quere' type. ('Private myQ
As New Queue')

"Cor Ligthert" <no************@planet.nl> schrieb im Newsbeitrag
news:ul**************@tk2msftngp13.phx.gbl...
TommyB,

What do you think that the result from a thread will be.

I know at least one, It will take some more time to get the IP address.

However when you want to test them all together in the same logical time,
than you can gain some performance when this is a kind of ping operation.

Use than a Queue wherin you have your structures.

Here in this message is a little sample of that from me with two
assynchroon working threads which give back the results.

http://groups-beta.google.com/group/...a15afdb6?hl=en

I hope this helps,

Cor

Nov 21 '05 #4

P: n/a
Addition: What must I import to use the Quere like in your example?
VB highlights it as error and it's not in the list appears alter typing the
new statement...
"Cor Ligthert" <no************@planet.nl> schrieb im Newsbeitrag
news:ul**************@tk2msftngp13.phx.gbl...
TommyB,

What do you think that the result from a thread will be.

I know at least one, It will take some more time to get the IP address.

However when you want to test them all together in the same logical time,
than you can gain some performance when this is a kind of ping operation.

Use than a Queue wherin you have your structures.

Here in this message is a little sample of that from me with two
assynchroon working threads which give back the results.

http://groups-beta.google.com/group/...a15afdb6?hl=en

I hope this helps,

Cor

Nov 21 '05 #5

P: n/a
Tommy,

I am using it at the moment in a programma with what I am busy with however
I have imported nothing.

Is it not a typo from you it is "Queue". As Charles Law (a regular in this
newsgroup and Englishman) forever write. From what he as Englishman becomes
crazy from (or something).

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor
Nov 21 '05 #6

P: n/a
hmmm, i had to do import 'System.Collections'.
Thanks for all, I will now test and use it :)
CYa!
"Cor Ligthert" <no************@planet.nl> schrieb im Newsbeitrag
news:%2****************@tk2msftngp13.phx.gbl...
Tommy,

I am using it at the moment in a programma with what I am busy with
however I have imported nothing.

Is it not a typo from you it is "Queue". As Charles Law (a regular in this
newsgroup and Englishman) forever write. From what he as Englishman
becomes crazy from (or something).

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.