10 Rules for Building a Windows Phone App: Listing 1.

Checking network availability.

public class Environment 
{
  public Environment()
  {
  myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 2, 0); // check every 2 Seconds 
  myDispatcherTimer.Tick += new EventHandler(CheckNetwork);
  myDispatcherTimer.Start();
}

public void CheckNetwork(object o, EventArgs sender)
{
  if (NetworkInterface.GetIsNetworkAvailable())
    return System.Windows.Visibility.Visible;
  else
    return System.Windows.Visibility.Collapsed;

  RaisePropertyChanged("IsNetworkAvailable");
  }

  public System.Windows.Visibility IsNetworkAvailable
{
  get
  {


    return _IsNetworkAvailable;
  }
  set
  {
    _IsNetworkAvailable = value;
    RaisePropertyChanged("IsNetworkAvailable");
  }
 }
}
  }
  }

About the Author

Max Zilberman is an architect evangelist at Microsoft on the Developer andPlatform Evangelism team and is available at mazilber@microsoft.com.