Is Task.Delay undocumented in .NET 4?

.net, task-parallel-library

Solution

This method does not exist in .NET 4.0.

You are probably ILspying 4.5. All of .NET 4.x's assemblies, through 4.5.2 at the time of this post, show v4.0.0.0, and newer versions replace older versions when you install them -- they're made to be backward compatible.

When you are able to grab `Task.Delay` through reflection, it's because your app is actually running on .NET 4.5.

When you select a framework version in Visual Studio, it will use whatever version you have installed, but only show the methods actually in that selection -- you can think of it as a compatibility selection, not so much an exact version selection.

I believe one of the Microsoft.Bcl and Microsoft.Bcl.Async packages on NuGet contains a `TaskEx.Delay` you can use which will emulate it on older frameworks and route to the build-in version when used on newer ones. These packages contain back-ported APIs.

Problem

I am currently using .NET 4 with Visual Studio 2010. MSDN said that `Task.Delay` is not available in this version of .NET framework. However, in my system ILdasm shows `Task.Delay` do exists in mscorlib (4.0.0.0). So I tested using reflection: ``` typeof (Task).GetMethod("Delay", new []{typeof (int)}) .Invoke(null, new object[]{1000}); ``` This seems to works on my computer. So my questions are: Is this means Microsoft provided that method somehow, but they are just hiding it? Is it safe to have a wrapper function to use it in above way? More precisely, would this work on other computers that only have .NET 4 installed? (my system is Windows 7) UPDATE I forgotten weather or not I had .NET 4.5 installed. So I checked from control panel. Yes, there is .NET 4.5.1 installed.

Original source

Related problems