how to find network status
I want to write a program in C# that recognize now computer connected to inter开发者_开发技巧net or not by C#. Would you help me how to do that, I have no idea about it,because I didnt work network in C#.
one more question,how I can run a program from c# and sent argument also?
Here is a simple example on how you can check if your computer is connected to the internet.
Here is another example on how to launch a program in C#. You can check this msdn page for more information on the Process
class.
You could use the GetHostEntry method to test DNS:
public static bool IsConnected()
{
try
{
var entry = Dns.GetHostEntry("www.google.com");
return true;
}
catch (SocketException ex)
{
return false;
}
}
As far as the second part of your question is concerned about command line arguments you would pass them at the command prompt:
c:\>foo.exe param1 param2
and you could fetch them as a string array in your Main method:
class Program
{
static void Main(string[] args)
{
// args will represent a string array of command line
// arguments passed to your application. It will be an
// empty array if no arguments were passed
}
}
精彩评论