default(CancellationToken) creates a CancellationToken , where m_source is null . You can see that by getting the value of this private field using reflection:
Console.WriteLine(typeof (CancellationToken). GetField("m_source", BindingFlags.NonPublic | BindingFlags.Instance). GetValue(default(CancellationToken)) ?? "null");
Output:
null
You can also see this by deleting only the corresponding field in the debugger:

So what is going on?
The debugger, in order to display the contents of the CancellationToken , accesses its properties one by one. When the internal CancellationTokenSource is null , the WaitHandle property creates and sets the default CancellationTokenSource before passing it to the WaitHandle property:
public WaitHandle WaitHandle { get { if (m_source == null) { m_source = CancellationTokenSource.InternalGetStaticSource(false); } return m_source.WaitHandle; } }
In conclusion, default(CancellationToken) and new CancellationToken create an empty structure where m_source is null , but looking at the structure in the debugger you fill this field with the default instance of CancellationTokenSource , which cannot be undone.
i3arnon Mar 30 '15 at 19:58 2015-03-30 19:58
source share