Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put a task to sleep (or delay) in C# 4.0?

There is Task.Delay in .NET 4.5

How can I do the same in .NET 4.0?

like image 456
Fulproof Avatar asked Mar 11 '13 15:03

Fulproof


People also ask

Is there a delay function in C?

The delay() function is built upon a C library function called clock(). The clock() function returns a time value in clock ticks, which is based on the processor's speed. The value returned is of the clock_t variable type. You can use subsequent reads of the clock() function to determine elapsed time.

What is sleep () in C?

The function sleep gives a simple way to make the program wait for a short interval. If your program doesn't use signals (except to terminate), then you can expect sleep to wait reliably throughout the specified interval.

How do you wait in C programming?

Insert, wherever you need your program to make a delay:sleep(1000); Change the "1000" to the number of milliseconds you want to wait (for example, if you want to make a 2 second delay, replace it with "2000".

How is delay calculated in embedded C?

The first method is simply using Loop program function in which Delay() function is made or by providing for(); delay loop in Embedded C programming. You can define your own value of delay and how long you want to display. For example- for(i=0;i<"any decimal value";i++); this is the delay for loop used in embedded C.


1 Answers

Use the Microsoft.Bcl.Async package from NuGet, it has TaskEx.Delay.

like image 92
Eli Arbel Avatar answered Oct 12 '22 17:10

Eli Arbel