0

I am currently working on an WinForm Application, we are currently using Surface Pros to run the application. However, the application freezes up when it loses WiFi. I want to bring a warning message when the surface loses wifi.

And another message when it finds connection again

I have tried using an AddressChangedCallBack event.. however everytime I lose wifi nothing happens.

below is my piece of code

static void AddressChangedCallback(object sender, EventArgs e)
{

  NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
    foreach (NetworkInterface n in adapters)
    {
        string _name = n.Name;
        OperationalStatus _operationalStatus = n.OperationalStatus;
        if (_name.Contains("WiFi"))
        {

           
            if (_operationalStatus == OperationalStatus.Down)
            {
               FriendlyMessageBox.Show("Sorry - network has lost connection"
                    + Environment.NewLine
                    + Environment.NewLine
                    + "You will lose your work if you close EIS"
                    , MessageBoxButtons.OK
                    , FriendlyMessageBox.FriendlyMessageBoxStyle.Warning
                    , "System Offline");
                //notification timer use
            }
            else if (_operationalStatus == OperationalStatus.Up)
            {
                FriendlyMessageBox.Show("Connection Found"
                + Environment.NewLine
                + Environment.NewLine
                + "Please continue on your work"
                , MessageBoxButtons.OK
                , FriendlyMessageBox.FriendlyMessageBoxStyle.Success
                , "System Connected");
                //notification timer use
            }
            else
            {
                //notification timer use
            }

any help would be greatly appreciated!

Mong Zhu
  • 23,309
  • 10
  • 44
  • 76
Ash
  • 1
  • 1
  • What kind of work your application does ? – UserNam3 Sep 13 '22 at 09:56
  • 1
    Does this answer your question? [I need a event to detect Internet connect/disconnect](https://stackoverflow.com/questions/4457773/i-need-a-event-to-detect-internet-connect-disconnect) – Charlieface Sep 13 '22 at 10:33

0 Answers0