Timer in Monodroid

Use of timer in monodroid, i take up this in Xamarin Studio.

Apply timer in xamarin studio like this first you need to declare ¬†“using System.Timers;” where you declare your assemblies. After this put the below code in your class

System.Timers.Timer t1;

protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);

t1 = new System.Timers.Timer(5000);
t1.Elapsed += new ElapsedEventHandler(OnTimeEvent);
t1.Interval = 5000;
t1.Enabled = true;
t1.Start();
//Initialize your stuff

 

}

 

private void OnTimeEvent(object source, ElapsedEventArgs e)
{
RunOnUiThread(delegate {
NewMethod ();
});

}

I hope this is what you looking for.

Leave a Reply