0

I'm working on ASP .Net Core project. Every time when the user try to do something or press some button I need to check WiFi status or connection or signal. In case that the status or connection or signal is low I want to save some info in session or cookies or maybe in DataBase.

I searched around and I found this as a potential solution. So I was thinking to do something like this :

private void timer1_Tick(object sender, EventArgs e)
       {
           bool connection = NetworkInterface.GetIsNetworkAvailable();
           if (connection == true)
           {
              //do nothing

           }
           else
           {
              //save some data
           }
       }

The problem is that if there is no WiFi signal, the program won't work and I can't save the data. So I need to save the data somehow before I lost the WiFi connection.

I allready read this and Detect wifi connectivity in c# ,but I have not found anything that maybe can help me. Also i saw that there are API that check WiFi connection, but I don't get it how to use it, and where should I call the method the check the WiFi status? I haven't tried any of these solutions yet, and i don't know if it works.

Any suggestions or examples?

Thanks in advance!

kvacka
  • 25
  • 6
  • A website does not have access to the device to check the signal. The examples you found are for winforms/wpf. – VDWWD Sep 18 '20 at 12:46
  • 1
    The question would make no sense unless the *web server* uses a WiFi connection. Which is a pretty bad idea. Using a timer with a web app is complicated too as there's no desktop or single thread. Each request gets processed on a separate thread, using new instances of the controllers, webpages or razor pages used by the stack – Panagiotis Kanavos Sep 18 '20 at 12:46
  • The thing that has a WiFi connection is the *browser*. If you want the browser to handle connectivity, you'd have to write Javascript code that can handle intermittent disconnections. This means SPA, workers, local storage. – Panagiotis Kanavos Sep 18 '20 at 12:48
  • Or you could create a Blazor web app. Both Blazor Server and Blazor Wasm handle connectivity and local storage (up to a point) and attempt to reconnect – Panagiotis Kanavos Sep 18 '20 at 12:49
  • So I can't do it in ASP .NET ? – kvacka Sep 18 '20 at 13:09
  • I once made something where if there was no connection then it wrote back to a cookie and then when it came back it wrote it back. I was using knockout and some knockout cookie plugin – Richard Housham Sep 18 '20 at 13:34

0 Answers0