Member-only story

Trigger C# functions on specific intervals

Jawadhasan
3 min readSep 22, 2021

--

Introduction

Sometimes we need to perform some action on specified intervals. For example I was working on an application where I needed to simulate some server actions to be triggered automatically. In this post, we will learn how can we build a simple solution to achieve this functionality.

Setting the Scene

I will be using an existing code base which utilized .NET Events. I wrote an article on this topic, which you can read if you need some background information about the code we’ll use today.

However, you can use your own existing code for such purpose as well.

Here is the application code for your reference:

The output of above code is shown as follows:

This starting code can be downloaded from this git repo (master branch).

Now, what we want is to call the printer.Print() method on specific interval e.g. after every two seconds.

Creating a custom SetInterval method

--

--

Jawadhasan
Jawadhasan

Written by Jawadhasan

Software Solutions Team Lead | Cloud Architect | Solutions Architect

Responses (1)