1、添加System.Windows.Forms的引用。
2、在命名空间上using一下。
3、要实现的部分:
using System;
using System.Runtime.InteropServices; using System.Windows.Forms;
namespace ThreadTest {
class Program {
[DllImport("winInet.dll ")] //声明外部的函数: private static extern bool InternetGetConnectedState( ref int dwFlag, int dwReserved );
static void Main(string[] args) {
int dwFlag = 0; if (!InternetGetConnectedState(ref dwFlag, 0)) Console.WriteLine("未联网!"); else { Console.WriteLine("联网!"); Thread.Sleep(2000); Application.Restart(); Environment.Exit(0); }
Console.ReadKey(); }
}
|
请发表评论