Perhaps this is a stupid question.
The class is Taskdeclared as follows:
public class Task : IThreadPoolWorkItem, IAsyncResult, IDisposable
An interface is IAsyncResultdeclared as follows:
public interface IAsyncResult
{
object AsyncState { get; }
WaitHandle AsyncWaitHandle { get; }
bool CompletedSynchronously { get; }
bool IsCompleted { get; }
}
But the member AsyncWaitHandledoes not exist in the class or instances Task.
This code:
System.Threading.Tasks.Task t = new System.Threading.Tasks.Task(() => { });
t.AsyncWaitHandle.ToString();
Causes a compilation error:
Error 1 'System.Threading.Tasks.Task' does not contain a definition for "AsyncWaitHandle" and no extension method "AsyncWaitHandle" Accepting the first argument of the type "System.Threading.Tasks.Task" may (do you miss the use directive or assembly reference? )
However, this is not only compiled:
System.IAsyncResult t = new System.Threading.Tasks.Task(() => { });
t.AsyncWaitHandle.ToString();
But also works, since the member exists. What kind of witchcraft is this?
Is this a compiler trick or is it hidden differently?
Greetings.