Kevin McMahon

Chicago based mobile developer.

Monotouch Quickie: Network Indicator Tip

I've used this simple technique below many times in WinForms apps to toggle the wait cursor (hourglass) during long running operations and it is applicable for the situations that call for toggling the network activity indicator in Monotouch.When used with a using statement, the indicator is turned on when the object is constructed and turned off when the code within the using statement has finished executing and the object's Dispose method is called.

public class NetworkIndicator : IDisposable{   public NetworkIndicator ()   {      UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true;   }   public void Dispose ()   {      UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false;            GC.SuppressFinalize(this);   }}


using(new NetworkIndicator()){    //Make network call here}

You wouldn't want to wrap this around a UIWebView (add the toggling of the indicator to the LoadStarted and LoadFinished events) but anytime your app is making calls out the network you can wrap the using statement around the method invocation and get the user friendly network activity notification.

Tagged: iphone / monotouch / apps / gc / c# / tips / network

blog comments powered by Disqus