Migz Migz - 1 year ago 234
Android Question

Xamarin Android C# Timer error

My android app uses a timer in a certain place.
I get an exception when the time exceeds an hour (3600000), it says the period is too large.

myTime = "3600000";

TempTimer = new System.Threading.Timer ((o) => {
ContentCheck(); // function call/ Void call <----------
}, null, 0, Int64.Parse(myTime) );

I've tried
already, so tried
(Hence it being in code..)

Is there a timer that can do an hour AND longer? Or perhaps and alternative method to get the same results as a timer?

Answer Source
Timer timer = new Timer();
        timer.Interval = 3600000; 
        timer.AutoReset = false; 
        timer.Start ();
        timer.Elapsed+= Timer_Elapsed;

    void Timer_Elapsed (object sender, ElapsedEventArgs e)
        Console.WriteLine("Timer has gone off");

Here the interval property of timer instance is of type Double. So that can store really large values. So this should work for you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download