Re: need help understanding this code snippet
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Thu, 28 Jul 2005 07:03:13 +0100
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
.
- References:
- Prev by Date: Re: Type conversions question
- Next by Date: RE: need help understanding this code snippet
- Previous by thread: need help understanding this code snippet
- Next by thread: RE: need help understanding this code snippet
- Index(es):