예제 #1
0
        public void Run(CancellationToken cancellationToken, ProfilingType profilingType)
        {
            Guard.NotNull(cancellationToken, nameof(cancellationToken));

            if (thread != null)
            {
                throw new InvalidOperationException();
            }

            thread = new Thread(() => {
                try {
                    Profiler profiler =
                        profilingType != ProfilingType.None ?
                        new Profiler(name, profilingType) :
                        null;
                    Do(cancellationToken, profiler);
                }
                catch (Exception error) {
                    this.error = error;
                    cancellationToken.Cancel();
                }
                finally {
                    outputChannel.Finish();
                }
            })
            {
                Name         = name,
                IsBackground = true
            };
            thread.Start();
        }