This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main() | |
{ | |
OuterOperationAsync().Wait(); | |
} | |
static async Task OuterOperationAsync() | |
{ | |
Console.WriteLine(LogicalFlow.CurrentOperationId); | |
using (LogicalFlow.StartScope()) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task task = Task.Run(async () => | |
{ | |
while (IsEnabled) | |
{ | |
await FooAsync(); | |
await Task.Delay(TimeSpan.FromSeconds(10)); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected internal override void QueueTask(Task task) | |
{ | |
if ((task.Options & TaskCreationOptions.LongRunning) != 0) | |
{ | |
// Run LongRunning tasks on their own dedicated thread. | |
Thread thread = new Thread(s_longRunningThreadWork); | |
thread.IsBackground = true; // Keep this thread from blocking process shutdown | |
thread.Start(task); | |
} | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Task<Task> task = Task.Factory.StartNew(async () => | |
{ | |
while (IsEnabled) | |
{ | |
await FooAsync(); | |
await Task.Delay(TimeSpan.FromSeconds(10)); | |
} | |
}, TaskCreationOptions.LongRunning); | |
Task actualTask = task.Unwrap(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var collectiveTimer = new CollectiveTimer<CancellationTokenSource>( | |
cts => cts.Cancel(), | |
TimeSpan.FromMilliseconds(200), | |
cancellationToken); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CollectiveTimer<T> | |
{ | |
private readonly ConcurrentQueue<QueueItem> _queue; | |
public CollectiveTimer(Action<T> action, TimeSpan timeout, CancellationToken cancellationToken) | |
{ | |
_queue = new ConcurrentQueue<QueueItem>(); | |
Task.Run(async () => | |
{ | |
while (!cancellationToken.IsCancellationRequested) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal bool Change(uint dueTime, uint period) | |
{ | |
bool success; | |
lock (TimerQueue.Instance) // Global lock. | |
{ | |
if (m_canceled) | |
throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_Generic")); | |
// prevent ThreadAbort while updating state |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal bool Change(uint dueTime, uint period) | |
{ | |
bool success; | |
lock (TimerQueue.Instance) | |
{ | |
if (m_canceled) | |
throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_Generic")); | |
// prevent ThreadAbort while updating state |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal bool Change(uint dueTime, uint period) | |
{ | |
bool success; | |
lock (TimerQueue.Instance) | |
{ | |
if (m_canceled) | |
throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_Generic")); | |
// prevent ThreadAbort while updating state |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main() | |
{ | |
for (var i = 0; i < Environment.ProcessorCount; i++) | |
{ | |
Task.Factory.StartNew(() => | |
{ | |
while (true) | |
{ | |
new Timer(_ => { }, null, TimeSpan.FromMilliseconds(100), Timeout.InfiniteTimeSpan); | |
} |