Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2007

Tip: Looking for answers? Try searching our database.

Network Availability detection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Folkien - 28 Aug 2007 11:10 GMT
Hello everybody.

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

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

namespace WindowsApplication2
{
 public delegate void MyApplication_NetworkAvailabilityChanged(object
sender, Microsoft.VisualBasic.Devices.NetworkAvailableEventArgs e);

 partial class Form1
 {
   /// <summary>
   /// Required designer variable.
   /// </summary>
   private System.ComponentModel.IContainer 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.Dispose();
     }
     base.Dispose(disposing);
   }

   #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 InitializeComponent()
   {
     this.button1 = new System.Windows.Forms.Button();
     this.label1 = new System.Windows.Forms.Label();
     this.SuspendLayout();
     //
     // button1
     //
     this.button1.Location = new System.Drawing.Point(92, 64);
     this.button1.Name = "button1";
     this.button1.Size = new System.Drawing.Size(125, 62);
     this.button1.TabIndex = 0;
     this.button1.Text = "button1";
     this.button1.UseVisualStyleBackColor = true;
     //
     // label1
     //
     this.label1.AutoSize = true;
     this.label1.Location = new System.Drawing.Point(56, 185);
     this.label1.Name = "label1";
     this.label1.Size = new System.Drawing.Size(35, 13);
     this.label1.TabIndex = 1;
     this.label1.Text = "label1";
     //
     // Form1
     //
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     this.ClientSize = new System.Drawing.Size(292, 273);
     this.Controls.Add(this.label1);
     this.Controls.Add(this.button1);
     this.Name = "Form1";
     this.Text = "Form1";
     this.ResumeLayout(false);
     this.PerformLayout();

     //
     // Network availability
     //
     this.netwatch = new NetworkWatching();
     this.netwatch.AvChange += new
MyApplication_NetworkAvailabilityChanged(this.netwat_AvChange);

   }

   #endregion

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

 class NetworkWatching
 {
   public event MyApplication_NetworkAvailabilityChanged AvChange;
 }
}

this is in the Form1.Designer.cs

In the Form1.cs I added :

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

   void netwat_AvChange(object sender,
Microsoft.VisualBasic.Devices.NetworkAvailableEventArgs e)
   {
     this.DisplayAvail(e.IsNetworkAvailable.ToString());
   }

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 - 28 Aug 2007 13:37 GMT
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
Michael Rubinstein - 28 Aug 2007 14:07 GMT
Folkejen, look up System.Net.NetworkInformation.NetworkChange class. It
has two public events - NetworkAvailabilityChanged and
NetworkAddressChanged. C# help for NetworkAddressChanged comes with code
fragment showing how to use this event. The other one can be handled in the
same manner.

   Michael

> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.