I've tried using System.windows.form
and System.Timers.Timer
but both are not recognize by visual studio 2017 xamarin form. This made me unable to create Timer time = new Timer(1000);
. How do we actually create and set the interval of a timer in C#? I need the full C# code of JavaScript setInterval(function(){ alert("Hello"); }, 3000);
for xamarin form.
Asked
Active
Viewed 790 times
-4

Vun
- 13
- 4
-
Check out https://stackoverflow.com/questions/12555049/timer-in-portable-library – Fruchtzwerg May 30 '17 at 07:37
3 Answers
1
I think you can take a look to StartTimer
public static Void StartTimer (TimeSpan interval, Func<bool> callback)
interval
The interval between invocations of the callback.
callback
The action to run when the timer elapses.
While the callback returns true, the timer will keep recurring.

Community
- 1
- 1

Alessandro Caliaro
- 5,623
- 7
- 27
- 52
0
public class Timer
{
CancellationTokenSource _cts = new CancellationTokenSource();
public Task Wait(TimeSpan delay)
{
return Task.Delay(delay, _cts.Token);
}
public void Stop()
{
_cts.Cancel();
}
}
usage:
var t = new Timer();
await t.Wait(TimeSpan.FromMinutes(30));

Zaheer Ul Hassan
- 771
- 9
- 24
0
I think you can use this:
await Task.Delay(3000);
DisplayAlert("Hello", "", "OK");

Menno K
- 79
- 1
- 11