首页 > 其他 > 详细

C#控制台程序自动重启(检测是否连接网络)

时间:2014-08-26 13:07:36      阅读:421      评论:0      收藏:0      [点我收藏+]

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();
}

}

C#控制台程序自动重启(检测是否连接网络)

原文:http://www.cnblogs.com/SeawinLong/p/3936846.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!