Exemplo n.º 1
0
        public void Dispose()
        {
            _innerSpan.Dispose();

            if (_active)
            {
                _traceContext.TryPop();
                _active = false;
            }
        }
Exemplo n.º 2
0
            public void Dispose()
            {
                if (_disposed)
                {
                    return;
                }

                _accessor.TryPop();
                _disposed = true;
            }
        // Inform the ThreadPool that there's work to be executed for this scheduler.
        private void NotifyThreadPoolOfPendingWork()
        {
            ISpan span = _traceContext.CurrentSpan;

            ThreadPool.UnsafeQueueUserWorkItem(_ =>
            {
                // Note that the current thread is now processing work items.
                // This is necessary to enable inlining of tasks into this thread.
                _currentThreadIsProcessingItems = true;
                try
                {
                    // Process all available items in the queue.
                    while (true)
                    {
                        Task item;
                        lock (_tasks)
                        {
                            // When there are no more items to be processed,
                            // note that we're done processing, and get out.
                            if (_tasks.Count == 0)
                            {
                                break;
                            }

                            // Get the next item from the queue
                            item = _tasks.First.Value;
                            _tasks.RemoveFirst();
                        }

                        try
                        {
                            _traceContext.Push(span);

                            // Execute the task we pulled out of the queue
                            base.TryExecuteTask(item);
                        }
                        finally
                        {
                            // Todo: clear the entire stack of active spans on this worker thread.
                            _traceContext.TryPop();
                        }
                    }
                }
                // We're done processing items on the current thread
                finally
                {
                    _currentThreadIsProcessingItems = false;
                }
            }, null);
        }