On Thu, 07 Jun 2007 09:09:43 -0700, <Ma*********@gmail.comwrote:
Thanks a bunch. I didn't realize that a Ping class existed in .Net.
It must be new to .Net 2.0. Anyways this worked great.
Note that a computer (or other network device) may have blocking or
disabled ping responses. So this method is only reliable if you know for
sure that the target device does in fact respond to pings.
Also note that pinging will tell you the state of the computer at the
moment that you ping it. Immediately after you ping it, the computer
could drop off the network or otherwise become unreachable. So you still
need to be able to handle the case when you try to connect but cannot.
I'm not aware of a way to specify a timeout when creating a FileStream
instance, though there may be one. However, you can implement it yourself
by using a separate thread to create the instance, with a waitable event
to signal to you when it's done. You can wait on a waitable event with a
timeout, so that allows you to specify the timeout. The tricky part is if
the thread creating the instance eventually succeeds, but after your
timeout. You need a way to deal with cleaning up the FileStream instance
in that case, but that should be as simple as setting a flag that the
thread can check to see whether it needs to clean up the instance or not.
Which method to use depends on just how reliably you need your goal to
accomplished. If you *never* want the user to have to wait the 8-10
seconds that it could take when timing out, then you need to implement
your timeout yourself (or figure out how to change the timeout inherent in
creating a FileStream instance). If you're okay with it being quick most
of the time, with the occasional chance for still waiting the timeout,
then the "ping" method should be just fine.
Pete