private static Task <bool> CompleteOnThreadPool() { var tcs = new TaskCompletionSource <bool>(); var local = new LocalTrace("childspan1"); var cur = TraceContextPropagation.CurrentSpan; local.Span.Should().Be(cur); ThreadPool.QueueUserWorkItem((_) => { // Thread.Sleep(20); var cur2 = TraceContextPropagation.CurrentSpan; cur2.Should().Be(local.Span); local.Dispose(); cur2 = TraceContextPropagation.CurrentSpan; // cur2.Should().Be(local.Span); tcs.SetResult(true); }); return(tcs.Task); }
private static Task <bool> CompleteWithCustomThread() { var tcs = new TaskCompletionSource <bool>(); var local = new LocalTrace("childspan3"); var cur = TraceContextPropagation.CurrentSpan; local.Span.Should().Be(cur); new Thread(() => { // Thread.Sleep(1); var cur2 = TraceContextPropagation.CurrentSpan; cur2.Should().Be(local.Span); local.Dispose(); tcs.SetResult(true); cur2 = TraceContextPropagation.CurrentSpan; }) { IsBackground = true }.Start(); return(tcs.Task); }
private Task <bool> CompleteOnThreadPool() { var tcs = new TaskCompletionSource <bool>(); var local = new LocalTrace("childspan1"); ThreadPool.QueueUserWorkItem((_) => { Thread.Sleep(50); local.Dispose(); tcs.SetResult(true); }); return(tcs.Task); }
private static Task <bool> CompleteWithinSpawnedTask() { var local = new LocalTrace("childspan2"); var cur = TraceContextPropagation.CurrentSpan; local.Span.Should().Be(cur); return(Task.Run(new Func <bool>(() => { // Thread.Sleep(20); var cur2 = TraceContextPropagation.CurrentSpan; cur2.Should().Be(local.Span); local.Dispose(); cur2 = TraceContextPropagation.CurrentSpan; // cur2.Should().Be(local.Span); return true; }))); }