private void Update()
{
var token = new CancellationTokenSource();
}
private void Update()
{
var token = new CancellationTokenSource();
}
public CancellationTokenSource()
{
m_state = NOT_CANCELED;
}
public CancellationTokenSource(TimeSpan delay)
{
long totalMilliseconds = (long)delay.TotalMilliseconds;
if (totalMilliseconds < -1 || totalMilliseconds > Int32.MaxValue)
{
throw new ArgumentOutOfRangeException("delay");
}
InitializeWithTimer((int)totalMilliseconds);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
if (m_disposed)
return;
if (m_timer != null) m_timer.Dispose();
var linkingRegistrations = m_linkingRegistrations;
if (linkingRegistrations != null)
{
m_linkingRegistrations = null; // free for GC once we're done enumerating
for (int i = 0; i < linkingRegistrations.Length; i++)
{
linkingRegistrations[i].Dispose();
}
}
// registered callbacks are now either complete or will never run, due to guarantees made by ctr.Dispose()
// so we can now perform main disposal work without risk of linking callbacks trying to use this CTS.
m_registeredCallbacksLists = null; // free for GC.
if (m_kernelEvent != null)
{
m_kernelEvent.Close(); // the critical cleanup to release an OS handle
m_kernelEvent = null; // free for GC.
}
m_disposed = true;
}
}
IDisposable
служит для реализации освобождения каких либо ресурсов. Сам по себе он к термину "неуправляемых ресурсов" отношения не имеет.private void Update()
{
var token = new CancellationTokenSource();
}
Является ли CancellationTokenSource неуправляемым ресурсом?
Если я напишу такой код. Получу ли я out memory exception с течением времени ?