Le réseau pour les développeurs > Forums - Accueil > Visual C# Language > Notify instead of Monitor Internet Connection Status
Poser une questionPoser une question
 

TraitéeNotify instead of Monitor Internet Connection Status

  • jeudi 5 novembre 2009 11:01Akeeq Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    Hi

    Some one please help me on how to monitor internet connection status. wheather is available or not.
    I have searched on this didn't find 

    what i found is

    1. NetworkChange.NetworkAvailabilityChanged event

    but this will only detect the network availability. I want a notification similar to this for internet connection availability. If there is network and only internet is gone then this will fail.


    2. Using a function to detect internet connection status (got several such function)

    this will work fine. but i have to put this in a thread to check condinously. Is that is the only way or is there any other way to get notification or will call event handler function like the previous. I think their will be one.

    or some body can tell where the windows will make entry in the registry for internet connection status. I know to make notification for a specific key on registry. Which if changes will call the notify-function.

    Please help me on how the internet related program (like messengers) are notified at the instance the internet is disconnected

    Thanks in Advance
    Akeeq
    • ModifiéAkeeq jeudi 5 novembre 2009 11:31more undestood
    •  

Réponses

Toutes les réponses

  • jeudi 5 novembre 2009 11:09Tamer OzMVPMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     A du code

    Hi,

    When programs such as messenger could not establish connection to their server they go into disconnected state.

    You can do the similar.

    You can ping a server at specific time intervals

                System.Net.NetworkInformation.Ping png = new System.Net.NetworkInformation.Ping();
                 try
                 {
                     PingReply rply = png.Send("www.bing.com");
                     Console.Write(rply.RoundtripTime.ToString());
                     Console.ReadLine();
                 }
                 catch (Exception)
                 {
                     Console.Write("Ping Error");
                     Console.ReadLine();
                 }
    

     

    Note:Using ip address instead of using domain might be a better way to prevent errors related to DNS.
  • jeudi 5 novembre 2009 11:26Akeeq Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    Hi

    Any one know how to create WMI internet connection notification function.

    i dont like to create thread or any timer which will consume CPU and memory

    but if that is the only way then please tell how it can impliment effectively.

    Thanks
  • jeudi 5 novembre 2009 11:34Tamer OzMVPMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     Réponse proposéeA du code
    Hi,

    Did some research and found that you can get this information with an api.

    Here is a sample.

            [DllImport("wininet.dll")]
            private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
    
            public static bool IsInternetConnectionAvailable()
            {
                int d;
                return InternetGetConnectedState(out d, 0);
            }
    
            static void Main()
            {
                Console.WriteLine(IsInternetConnectionAvailable());
                Console.ReadKey();
            }
    
    • Proposé comme réponseTamer OzMVPvendredi 6 novembre 2009 12:11
    •  
  • samedi 7 novembre 2009 11:52Akeeq Médailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     
    Hi

    I know my English is poor. But now i realized how much deep it is

    Please ...

    i know how to get connection status
    what i need is a call back or notification function when ever internet connection status changes

    If their is no such thing, please tell that  or how can i implement this


  • samedi 7 novembre 2009 11:58Tamer OzMVPMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     Traitée
    • Marqué comme réponseAkeeq mercredi 11 novembre 2009 10:51
    •  
  • lundi 9 novembre 2009 07:20Harry ZhuMSFT, ModérateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateurMédailles de l'utilisateur
     Traitée
    Hi,

    As far as I can see, this kind of event does not exist.
    We might need to query every time using timer.

    I believe messagers get notifications when they sent information but do not get response. They will not receive notification when the internet status is changed.

    Harry
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marqué comme réponseAkeeq mercredi 11 novembre 2009 10:50
    •