在检查互联网连接后,尝试关闭表单时,c#计时器为空

时间:2018-07-13 10:30:49

标签: c#

首先,我有一个检查互联网连接的功能。它仅与消息框一起使用,以显示以下代码的结果:

//Tikrinam Yra Netas ar ne.
bool con = NetworkInterface.GetIsNetworkAvailable();
if (con == true)
{
    timer7.Start();
    timer7.Enabled = true;
    timer7.Interval = 10000;
    var popupNotifier = new PopupNotifier();
    popupNotifier.TitleText = " Susscesfully Connected to 3Nematic.NET";
    popupNotifier.TitleColor = Color.BlueViolet;
    //Image
    Image img = Properties.Resources.Cancel_48px; // Cancel
    popupNotifier.Image = img;
    popupNotifier.HeaderColor = Color.Purple;
    // Access Iki:
    popupNotifier.ContentText = " We can't connect you to servers\n " + "Because you're not connected to WiFi Services" + "\n To Connect, you have to get Internet Connection fully working.";
    popupNotifier.IsRightToLeft = false;
    popupNotifier.Popup();
    popupNotifier.ShowCloseButton = true;
    popupNotifier.ShowGrip = true;
    //Parodom, kad yra
}
else
{
    var popupNotifier = new PopupNotifier();
    popupNotifier.TitleText = " Failed to LOG-IN. ";
    popupNotifier.TitleColor = Color.BlueViolet;
    //Image
    Image img = Properties.Resources.Cancel_48px; // Cancel
    popupNotifier.Image = img;
    popupNotifier.HeaderColor = Color.Purple;
    // Access Iki:
    popupNotifier.ContentText = " We can't connect you to servers\n " + "Because you're not connected to WiFi Services" + "\n To Connect, you have to get Internet Connection fully working.";
    popupNotifier.IsRightToLeft = false;
    popupNotifier.Popup();
    popupNotifier.ShowCloseButton = true;
    popupNotifier.ShowGrip = true;
    //Isjungs ir  nieko nerodys, tai reik timerio kursim timer7 koki
}

我还添加了一个弹出窗口。最后,我有一个尚未在代码中的计时器。弹出窗口显示10秒后,该计时器将关闭应用程序。互联网打开时,弹出窗口可以正常工作。但是,当互联网关闭时,我正在暂停表单,并且出现此错误:System.Net.WebException: 'The remote name could not be resolved: 'google.com''

此功能可以获取正在使用该应用的所有人的IP。

//Gavimas ip
private string Gaunamip()
{
    string ip = new WebClient().DownloadString("http://google.com");
    ip = ip.Replace("\n", "");
    return ip;
}

enter image description here

PS 感谢您的帮助。

0 个答案:

没有答案