Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a non blocking C# method at regular intervals?

Tags:

c#

.net

I have a C# Class. I need to execute its instance at regular intervals say 5 minutes. I need to execute this code every 5 minutes without blocking the main thread. Also I would like to have a mechanism where I can stop this process.

like image 962
Kunal Deo Avatar asked May 27 '11 18:05

Kunal Deo


People also ask

What is non-blocking IO in C?

Sometimes it's convenient to have I/O that doesn't block i.e we don't want a read call to block on one in case of input from the other. Solution for this is the given function: To specify non-blocking option: #include<fcntl. h> int fd; fcntl(fd, F_SETFL, O_NONBLOCK);

Does read () block in C?

By default, read() waits until at least one byte is available to return to the application; this default is called “blocking” mode.

Is write a blocking call in C?

Yes, absolutely. If the write buffer is full, the write can block.

What is blocking in C?

Blocking a signal means telling the operating system to hold it and deliver it later. Generally, a program does not block signals indefinitely—it might as well ignore them by setting their actions to SIG_IGN . But it is useful to block signals briefly, to prevent them from interrupting sensitive operations.


1 Answers

Check out the Timer class.

like image 157
Justin Niessner Avatar answered Oct 12 '22 23:10

Justin Niessner