i want a timer, that runs in the background. After about 10 seconds the timer should stop tasks or update my Layout. How can I do this?
You can make use of Alarm Manager.
that is not what i'm searching for. I need a background timer during the user is working with the app.
I don't know if this is still an open topic, but you can create a timer task of your own.
Create an extension method on "TaskFactory"
/// Start a new task that will run continuously for a given amount of time.
/// <param name="taskFactory">Provides access to factory methods for creating System.Threading.Tasks.Task and System.Threading.Tasks.Task`1 instances.</param>
/// <param name="action">The action delegate to execute asynchronously.</param>
/// <param name="cancellationToken">The System.Threading.Tasks.TaskFactory.CancellationToken that will be assigned to the new task.</param>
/// <param name="timeSpan">The interval between invocations of the callback.</param>
/// <returns>The started System.Threading.Tasks.Task.</returns>
public static Task StartNewTaskContinuously(this TaskFactory taskFactory, Action action, CancellationToken cancellationToken, TimeSpan timeSpan)
return taskFactory.StartNew(async () =>
Now all you have to do is call this method the same way you start another Task:
CancellationToken token = _cancellationSource.Token;
// Do stuff
Maybe there are better solutions (if so, please let me know) but this worked for me.
Xamarin Inc., as a wholly-owned Microsoft subsidiary acting as a separate legal entity, adheres to the Microsoft Privacy Statement: Privacy & cookies