Question on using C# IsDestinationReachable function

Hi, I am an SMS administrator for our Company. It seems on a daily basis I have to connect to computers to fix something related to SMS. Well we have a large remote user base and frequently those machines are not connected when I need to do something to them. So I suppose I could try to remember to ping them throughout the day or set up a ping -t command, but that seemed wasteful. So as a beginning c# hobbyist (won't say programmer just yet), I broke out my Visual C# Express 2005 and thought how could I automate this task of finding out when a computer comes online? So I found out about the function IsDestinationReachable using a DLL Import within c#.

I set up a window to ask for a computer name, then pass that computer name to the next window that does the actual checking. If it does not reach the given machine, it sleeps for 30 seconds then tries again. Once the machine is reached, the window pops up on the display and an audible tone is also generated.

Well this seems to work for most machines. However, I have seen this app tell me a machine is now online when it is sitting right next to me, turned off, and unplugged from the network. If I try to ping the machine, I get no reply, as I would expect.

I have listed my code below. Can anyone offer some thoughts, hints, etc.?
-------------------------------------------------------------------------------------------------------
        private void frmWaitForActive_Load(object sender, EventArgs e)
        {
            //set window title and hide window.
            Text = "Is " + strCompName + " online?";
            this.Hide();

            /*This section of code will perform the actual test of
             * determining whether the indicated computer is reachable.
             *
             * A boolean variable is initially set to false, then the
             * function called IsDestinationReachable is run using the
             * supplied computer name as the host.
             *
             * If the host is reachable, then a window will display
             * for the user indicating such, as well as a tone will sound
             * as an audible indicator.
             *
             * If the host is not found, then the program sleeps
             * for 30 seconds (30000 milliseconds) and the process
             * is then repeated to check if the host is reachable.
             */
            bool blnFlag = false;
            while (blnFlag == false)
            {      
                if (IsDestinationReachable(strCompName, IntPtr.Zero))
                {
                    //the host is reachable. Now notify the administrator
                    WindowState = FormWindowState.Normal;
                    txtCompName.Text = strCompName + " is now on-line!";
                    this.Show();
                    blnFlag = true;
                    Beep(500, 550);
                }
                else
                {
                    //Sleep 30 seconds (30000 milliseconds)
                    Thread.Sleep(30000);
                }
            }
        }


Thanks for any ideas.
Michael
MichaelCohoonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Michael,

IsDestinationReachable uses a Ping to check the status, so I fail to see what you are saving by using this API call.

Bob

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MichaelCohoonAuthor Commented:
Bob, I think I can do the code to start a ping command, using the Process.Start, but I really don't have a clue how I would be able to determine if I receive a response or not via code. Would that check be something easily done?

Michael
MichaelCohoonAuthor Commented:
Bob, you gave me an idea to go the way of Ping. So a search on google for "C# ping status" turned up code for me. .Net 2.0 now includes network functions that are relatively easy to use, including a ping. So I will go that route with my program.

I thank you for the idea.
Michael
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.