Beispiel #1
0
        public void DependentToken_API_use()
        {
            var monitor = new ActivityMonitor();

            monitor.Output.CreateBridgeTo(TestHelper.ConsoleMonitor.Output.BridgeTarget);

            using (monitor.OpenTrace().Send("Create token and dependent monitor."))
            {
                // Creates the token.
                var token = monitor.DependentActivity().CreateToken();
                // Creates a dependent monitor.
                using (var monitorDep = token.CreateDependentMonitor(m => m.Output.CreateBridgeTo(TestHelper.ConsoleMonitor.Output.BridgeTarget)))
                {
                    monitor.Trace().Send("Doing something...");
                    // ...
                }
            }
            using (monitor.OpenTrace().Send("Create token with delayed launch of the dependent activity."))
            {
                // Creates the token.
                var token = monitor.DependentActivity().CreateToken(delayedLaunch: true);
                // Signals the launch of the dependent activity.
                monitor.DependentActivity().Launch(token);
                // Creates a dependent monitor.
                using (var monitorDep = token.CreateDependentMonitor(m => m.Output.CreateBridgeTo(TestHelper.ConsoleMonitor.Output.BridgeTarget)))
                {
                    monitor.Trace().Send("Doing something...");
                    // ...
                }
            }
            using (monitor.OpenTrace().Send("Starting a dependent activity on an existing monitor."))
            {
                // Creates the token.
                var token = monitor.DependentActivity().CreateToken();

                IActivityMonitor wMonitor = monitor;
                using (wMonitor.StartDependentActivity(token))
                {
                    wMonitor.Trace().Send("Doing something...");
                    // ...
                }
            }
        }