Network Availability detection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Folkien

    #1

    Network Availability detection

    Hello everybody.

    I want to make a little programme to show the network availability
    status. I read that I had to use
    Microsoft.Visua lBasic.Devices, creat a delegate to manage the event.

    Here is the code that I made but of course it dosn't work

    namespace WindowsApplicat ion2
    {
    public delegate void MyApplication_N etworkAvailabil ityChanged(obje ct
    sender, Microsoft.Visua lBasic.Devices. NetworkAvailabl eEventArgs e);

    partial class Form1
    {
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.Componen tModel.IContain er components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing ">true if managed resources should be
    disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
    if (disposing && (components != null))
    {
    components.Disp ose();
    }
    base.Dispose(di sposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeCompo nent()
    {
    this.button1 = new System.Windows. Forms.Button();
    this.label1 = new System.Windows. Forms.Label();
    this.SuspendLay out();
    //
    // button1
    //
    this.button1.Lo cation = new System.Drawing. Point(92, 64);
    this.button1.Na me = "button1";
    this.button1.Si ze = new System.Drawing. Size(125, 62);
    this.button1.Ta bIndex = 0;
    this.button1.Te xt = "button1";
    this.button1.Us eVisualStyleBac kColor = true;
    //
    // label1
    //
    this.label1.Aut oSize = true;
    this.label1.Loc ation = new System.Drawing. Point(56, 185);
    this.label1.Nam e = "label1";
    this.label1.Siz e = new System.Drawing. Size(35, 13);
    this.label1.Tab Index = 1;
    this.label1.Tex t = "label1";
    //
    // Form1
    //
    this.AutoScaleD imensions = new System.Drawing. SizeF(6F, 13F);
    this.AutoScaleM ode = System.Windows. Forms.AutoScale Mode.Font;
    this.ClientSize = new System.Drawing. Size(292, 273);
    this.Controls.A dd(this.label1) ;
    this.Controls.A dd(this.button1 );
    this.Name = "Form1";
    this.Text = "Form1";
    this.ResumeLayo ut(false);
    this.PerformLay out();

    //
    // Network availability
    //
    this.netwatch = new NetworkWatching ();
    this.netwatch.A vChange += new
    MyApplication_N etworkAvailabil ityChanged(this .netwat_AvChang e);

    }

    #endregion

    private System.Windows. Forms.Button button1;
    private NetworkWatching netwatch;
    private System.Windows. Forms.Label label1;
    }

    class NetworkWatching
    {
    public event MyApplication_N etworkAvailabil ityChanged AvChange;
    }
    }

    this is in the Form1.Designer. cs

    In the Form1.cs I added :

    private void DisplayAvail(st ring avail)
    {
    label1.Text = avail;
    }

    void netwat_AvChange (object sender,
    Microsoft.Visua lBasic.Devices. NetworkAvailabl eEventArgs e)
    {
    this.DisplayAva il(e.IsNetworkA vailable.ToStri ng());
    }

    Any idea what i have to do to make what i want ? I now that probably I
    miss a conceptual clarification.

    Anyway, thx a lot for the help

  • Folkien

    #2
    Re: Network Availability detection

    Ok I went an other way, I try now to use the WMI api. I have to find
    what is the event linked to network managment to make my query but It
    seam's much easier

    Comment

    • Michael Rubinstein

      #3
      Re: Network Availability detection

      Folkejen, look up System.Net.Netw orkInformation. NetworkChange class. It
      has two public events - NetworkAvailabi lityChanged and
      NetworkAddressC hanged. C# help for NetworkAddressC hanged comes with code
      fragment showing how to use this event. The other one can be handled in the
      same manner.

      Michael

      "Folkien" <johnsonclair@h otmail.comwrote in message
      news:1188304646 .876411.8710@o8 0g2000hse.googl egroups.com...
      Ok I went an other way, I try now to use the WMI api. I have to find
      what is the event linked to network managment to make my query but It
      seam's much easier
      >

      Comment

      Working...