Пример #1
0
        private void MicroThreadCallbackStart(object sender, SchedulerThreadEventArgs e)
        {
            TimeInterval timeInterval;
            int          intervalCount;

            lock (threadExecutionIntervals)
            {
                List <TimeInterval> intervals = threadExecutionIntervals[e.ThreadId];
                if (intervals.Count > 0 && !intervals.Last().HasEnded)
                {
                    throw new InvalidOperationException("Starting a new microthread on a thread still running another microthread.");
                }

                timeInterval = new TimeInterval(GetTicksFromStopwatch());
                intervals.Add(timeInterval);
                intervalCount = intervals.Count;
            }

            // Rely on intervals.Count, so must be called after intervals.Add!
            long jobId   = GetMicrothreadJobIdFromThreadInfo(e.ThreadId, intervalCount);
            var  jobInfo = new MicrothreadNotification(e.ThreadId, e.MicroThread.Id, jobId, timeInterval.StartTime, MicrothreadNotification.NotificationType.JobStarted);

            lock (microthreadNotifications)
            {
                microthreadNotifications.Add(jobInfo);
            }
        }
Пример #2
0
        private void MicroThreadCallbackEnd(object sender, SchedulerThreadEventArgs e)
        {
            long endTime = GetTicksFromStopwatch();
            int  intervalCount;

            lock (threadExecutionIntervals)
            {
                List <TimeInterval> intervals = threadExecutionIntervals[e.ThreadId];
                intervals.Last().End(endTime);
                intervalCount = intervals.Count;
            }
            long jobId   = GetMicrothreadJobIdFromThreadInfo(e.ThreadId, intervalCount);
            var  jobInfo = new MicrothreadNotification(e.ThreadId, e.MicroThread.Id, jobId, endTime, MicrothreadNotification.NotificationType.JobEnded);

            lock (microthreadNotifications)
            {
                microthreadNotifications.Add(jobInfo);
            }
        }