Esempio n. 1
0
        public void CaptureExecutionContext(bool captureSyncContext = false)
        {
            if (!_allowExecutionContextFlow)
            {
                return;
            }

            if (captureSyncContext)
            {
                _сapturedContext = ExecutionContext.Capture();
            }
            else
            {
                _сapturedContext = ExecutionContextHelper.CaptureContextNoSyncContext();
            }
        }
Esempio n. 2
0
        private static void CapturePerfNew(int elemCount)
        {
            ExecutionContext data = ExecutionContextHelper.CaptureContextNoSyncContext();
            ContextCallback  clb  = new ContextCallback(ExecutionMethod);

            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

            Stopwatch sw = Stopwatch.StartNew();

            for (int i = 0; i < elemCount; i++)
            {
                data = ExecutionContextHelper.CaptureContextNoSyncContext();
                ExecutionContextHelper.RunInContext(data, clb, null, true);
                //DoWithContext(data);
            }

            sw.Stop();

            Console.WriteLine("CapturePerfNew. Time = " + sw.ElapsedMilliseconds.ToString() + "ms");
            Console.WriteLine();
        }