The recent Visual Studio 11 Beta version has a new and major built-in feature of the future C # 5 - asynchronous programming using async/await. In this article I would like to structure and examine this quite interesting new tool and share the results with you.
Why is it needed?
C# is actively developing language. Each its version has interesting features that really simplify the writing quality of understandable code. For example, Linq considerably simplified the writing of filters for collections and sql queries in the code. Now the turn came for asynchrony.
Unlike most assemblers, the result of multiplication has the same number of digits as the multipliers in C / C + +. In order not to lose the accuracy, sometimes it is needed to perform additional operations for the multiplication.
Let us consider the task. The system determines the time since starting the program in the microprocessor’s ticks by calling the function:
unsigned long long getTickCount ();
Length unsigned long long - 64 bits. Converting to the physical units of time in the system, there is a constant:
const unsigned long long TICKS_PER_SECOND = 1999000000ULL;
It is required to determine the function of transferring ticks in a nanoseconds getNsec (unsigned long long ticks) with semantics:
unsigned long long getNsecNaive (unsigned long long ticks) {
static const unsigned long long NSEC_PER_SECOND = 1000000000ULL;
unsigned long long nsec = NSEC_PER_SECOND * ticks / TICKS_PER_SECOND;
return nsec;
}