Re: need help understanding this code snippet

Tech-Archive recommends: Fix windows errors by optimizing your registry



mb <mb@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
> got the following code snippet that i've modified off the internet to work -
> but damn if i know how and i dont like that. im having trouble with the
> following thread declaration that creates the thread, calls the ScanPorts
> method in the ScanPorts class and somehow passes in the array list
> scannedSystems. i'm stumped - how does it do all that on one line? thanks
> all.
>
> private ArrayList scannedSystems;
> scannedSystems.Add(new ScanPorts(ipAddress, port);
> Thread scanThread = new Thread ( new ThreadStart
> (((ScanPorts)scannedSystems[0]).systemScan));
> scanThread.Start();

It's not doing it all on one line - and it's not actually working,
either.

private ArrayList scannedSystems; // Declaring the ArrayList

Presumably somewhere it's actually *instantiating* the ArrayList too...

// Add an element to the list
scannedSystems.Add(new ScanPorts(ipAddress, port);

// Create a new thread which will run the systemScan method
// of the first element of the list (this is why there's a bug - it
// should be the *last* element of the list)
Thread scanThread = new Thread ( new ThreadStart
(((ScanPorts)scannedSystems[0]).systemScan));

// Start the new thread
scanThread.Start();

Mind you, it doesn't seem to actually do anything in terms of results,
either - there's nothing in ScanPorts to record whether or not it
managed to connect.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.