winform判断是否连接网络

C#判断是否连接网络

怎么判断网络是否连接

	/// <summary>
		/// 是否可以上网
		/// </summary>
		/// <param name="dwFlag"></param>
		/// <param name="dwReserved"></param>
		/// <returns></returns>
		[System.Runtime.InteropServices.DllImport("winInet.dll")]
		private static extern bool InternetGetConnectedState(ref int dwFlag, int dwReserved);
		/// <summary>
		/// 是否连接网络
		/// </summary>
		/// <returns></returns>
		public static bool NetworkIsLink()
		{
			Int32 flags = new int();
			bool netWorkIsLink = InternetGetConnectedState(ref flags, 0);
			return netWorkIsLink;
		}
bool bo = NetworkIsLink();
			if (!bo)
			{
				MessageBox.Show("没有可用的网络连接,请检查网络设置", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
				Application.Exit();
				return;
			}