public void TestMethod1() { m_task = new ScheduledTask(ThreadingMode.DedicatedBackground,ThreadPriority.Highest); m_task.Running += task_Running; m_task.Start(10); Thread.Sleep(1000); m_task.Dispose(); System.Console.WriteLine("Disposed"); }
public Monitor(int delay) { m_logSmall = Log.RegisterEvent(MessageLevel.Info, MessageFlags.SystemHealth, $"ThreadPool Small Delay Variance ({delay} ms)", 0, MessageRate.EveryFewSeconds(10), 5); m_logMedium = Log.RegisterEvent(MessageLevel.Warning, MessageFlags.SystemHealth, $"ThreadPool Medium Delay Variance ({delay} ms)", 0, MessageRate.EveryFewSeconds(10), 5); m_logLarge = Log.RegisterEvent(MessageLevel.Error, MessageFlags.SystemHealth, $"ThreadPool Large Delay Variance ({delay} ms)", 0, MessageRate.EveryFewSeconds(10), 5); m_logSmall.ShouldRaiseMessageSupressionNotifications = false; m_logMedium.ShouldRaiseMessageSupressionNotifications = false; m_logLarge.ShouldRaiseMessageSupressionNotifications = false; m_delay = delay; m_time = null; m_task = new ScheduledTask(); m_task.Running += task_Running; }
/// <summary> /// Creates a LogFileWriter that initially queues message /// </summary> /// <param name="messageLimit">the number of messages to maintain</param> public LogSubscriptionFileWriter(int messageLimit) { m_processName = Process.GetCurrentProcess().ProcessName; m_fileSequenceNumber = 1; m_syncRoot = new object(); m_maxQueue = messageLimit; m_messageQueue = new ConcurrentQueue<LogMessage>(); m_flushTask = new ScheduledTask(); m_flushTask.Running += m_flushTask_Running; m_verbose = VerboseLevel.High; m_subscriber = Logger.CreateSubscriber(m_verbose); m_subscriber.SubscribeToAll(m_verbose); m_subscriber.NewLogMessage += SubscriberNewLogMessage; }
void TestTimed(ThreadingMode mode) { const int Count = 1000000000; Stopwatch sw = new Stopwatch(); m_doWorkCount = 0; using (ScheduledTask work = new ScheduledTask(mode)) { work.Running += work_DoWork; sw.Start(); for (int x = 0; x < 1000; x++) { work.Start(1); work.Start(); } sw.Stop(); } m_doWorkCount = 0; sw.Reset(); using (ScheduledTask work = new ScheduledTask(mode)) { work.Running += work_DoWork; sw.Start(); for (int x = 0; x < Count; x++) { work.Start(1000); work.Start(); } sw.Stop(); } Console.WriteLine(mode.ToString()); Console.WriteLine(" Fire Event Count: " + m_doWorkCount.ToString()); Console.WriteLine(" Fire Event Rate: " + (m_doWorkCount / sw.Elapsed.TotalSeconds / 1000000).ToString("0.00")); Console.WriteLine(" Total Calls Time: " + sw.Elapsed.TotalMilliseconds.ToString("0.0") + "ms"); Console.WriteLine(" Total Calls Rate: " + (Count / sw.Elapsed.TotalSeconds / 1000000).ToString("0.00")); Console.WriteLine(); }
public Consumer(IAdapter adapter) { Methods = (adapter as IOptimizedRoutingConsumer)?.GetRoutingPassthroughMethods(); if (Methods == null) { if (adapter is IActionAdapter) { m_callback = ((IActionAdapter)adapter).QueueMeasurementsForProcessing; } else { m_callback = ((IOutputAdapter)adapter).QueueMeasurementsForProcessing; } m_task = new ScheduledTask(); m_task.Running += m_task_Running; m_pendingMeasurements = new ConcurrentQueue<List<IMeasurement>>(); MeasurementsToRoute = new List<IMeasurement>(); } }
/// <summary> /// Creates a <see cref="LoggerInternal"/>. /// </summary> public LoggerInternal(out LoggerInternal loggerClass) { //Needed to set the member variable of Logger. //This is because ScheduleTask will call Logger before Logger's static constructor is completed. loggerClass = this; m_syncRoot = new object(); m_typeIndexCache = new Dictionary<Type, LogPublisherInternal>(); m_allPublishers = new List<LogPublisherInternal>(); m_subscribers = new List<WeakReference>(); m_messages = new ConcurrentQueue<Tuple<LogMessage, LogPublisherInternal>>(); // Since ScheduledTask calls ShutdownHandler, which calls Logger. This initialization method cannot occur // until after the Logger static class has finished initializing. m_calculateRoutingTable = new ScheduledTask(); m_calculateRoutingTable.Running += CalculateRoutingTable; m_calculateRoutingTable.IgnoreShutdownEvent(); m_routingTask = new ScheduledTask(ThreadingMode.DedicatedForeground); m_routingTask.Running += RoutingTask; m_routingTask.IgnoreShutdownEvent(); }
/// <summary> /// Stops the timer. The call that stops the timer /// will pause until the event is stopped. Any subsequent /// calls will return immediately. /// </summary> public void Stop() { lock (m_syncRoot) { if (!m_isRunning) { return; } if (m_stopping) { return; } m_stopping = true; } m_timer.Dispose(); lock (m_syncRoot) { m_timer = null; m_stopping = false; m_isRunning = false; } Log.Publish(MessageLevel.Info, "EventTimer Started"); }
/// <summary> /// Attempts to connect to data input source. /// </summary> protected override void AttemptConnection() { m_nextPublicationTime = ToPublicationTime(DateTime.UtcNow.Ticks); m_nextPublicationTimeWithLatency = m_nextPublicationTime + (long)(m_latency.Next() * TimeSpan.TicksPerMillisecond); if ((object)m_timer == null) { m_timer = new ScheduledTask(ThreadingMode.ThreadPool); m_timer.Running += m_timer_Running; } if ((object)m_statusUpdate == null) { m_statusUpdate = new ScheduledTask(ThreadingMode.ThreadPool); m_statusUpdate.Running += m_statusUpdate_Running; } m_timer.Start(); m_statusUpdate.Start(10000); }
void TestConcurrent(ThreadingMode mode) { int workCount; const int Count = 100000000; Stopwatch sw = new Stopwatch(); m_doWorkCount = 0; using (ScheduledTask work = new ScheduledTask(mode)) { work.Running += work_DoWork; sw.Start(); for (int x = 0; x < 1000; x++) work.Start(); sw.Stop(); } m_doWorkCount = 0; sw.Reset(); using (ScheduledTask work = new ScheduledTask(mode)) { work.Running += work_DoWork; sw.Start(); ThreadPool.QueueUserWorkItem(BlastStartMethod, work); ThreadPool.QueueUserWorkItem(BlastStartMethod, work); for (int x = 0; x < Count; x++) work.Start(); workCount = m_doWorkCount; sw.Stop(); Thread.Sleep(100); } Console.WriteLine(mode.ToString()); Console.WriteLine(" Fire Event Count: " + workCount.ToString()); Console.WriteLine(" Fire Event Rate: " + (workCount / sw.Elapsed.TotalSeconds / 1000000).ToString("0.00")); Console.WriteLine(" Total Calls Time: " + sw.Elapsed.TotalMilliseconds.ToString("0.0") + "ms"); Console.WriteLine(" Total Calls Rate: " + (Count / sw.Elapsed.TotalSeconds / 1000000).ToString("0.00")); Console.WriteLine(); }
/// <summary> /// Creates a new instance of the <see cref="SharedTimerScheduler"/> class. /// </summary> public SharedTimerScheduler() { m_syncRoot = new object(); m_log = Logger.CreatePublisher(typeof(SharedTimerScheduler), MessageClass.Component); m_schedulesByInterval = new Dictionary<int, SharedTimerInstance>(); m_reportStatus = new ScheduledTask(); m_reportStatus.Running += ReportStatus; m_reportStatus.Start(60 * 1000); }
/// <summary> /// Creates a new instance of the <see cref="LongSynchronizedOperation"/> class. /// </summary> /// <param name="action">The action to be performed during this operation.</param> /// <param name="exceptionAction">The action to be performed if an exception is thrown from the action.</param> /// <param name="isBackground">Specifies if this operation will be a background thread.</param> public DedicatedSynchronizedOperation(Action action, Action<Exception> exceptionAction, bool isBackground) : base(action, exceptionAction) { m_task = isBackground ? new ScheduledTask(ThreadingMode.DedicatedBackground) : new ScheduledTask(ThreadingMode.DedicatedForeground); m_task.Running += m_task_Running; }
protected override void Dispose(bool disposing) { if (!m_disposed) { m_disposed = true; m_timer?.Dispose(); m_timer = null; } base.Dispose(disposing); }
/// <summary> /// Starts the watching /// </summary> public void Start(ThreadingMode mode = ThreadingMode.ThreadPool) { if (m_started) return; m_started = true; Log.Publish(MessageLevel.Debug, "EventTimer Started"); m_timer = new ScheduledTask(mode); m_timer.Running += TimerRunning; RestartTimer(); }
/// <summary> /// Creates a new instance of the <see cref="LongSynchronizedOperation"/> class. /// </summary> /// <param name="action">The action to be performed during this operation.</param> /// <param name="exceptionAction">The action to be performed if an exception is thrown from the action.</param> /// <param name="isBackground">Specifies if this operation will be a background thread.</param> public DedicatedSynchronizedOperation(Action action, Action <Exception> exceptionAction, bool isBackground) : base(action, exceptionAction) { m_task = isBackground ? new ScheduledTask(ThreadingMode.DedicatedBackground) : new ScheduledTask(ThreadingMode.DedicatedForeground); m_task.Running += m_task_Running; }
/// <summary> /// Creates a <see cref="RouteMappingHighLatencyLowCpu"/> /// </summary> public RouteMappingHighLatencyLowCpu() { m_lastStatusUpdate = ShortTime.Now; m_maxPendingMeasurements = 1000; m_routeLatency = OptimizationOptions.RoutingLatency; m_batchSize = OptimizationOptions.RoutingBatchSize; m_inboundQueue = new ConcurrentQueue<List<IMeasurement>>(); m_task = new ScheduledTask(ThreadingMode.DedicatedBackground, ThreadPriority.AboveNormal); m_task.Running += m_task_Running; m_task.UnhandledException += m_task_UnhandledException; m_task.Disposing += m_task_Disposing; m_task.Start(m_routeLatency); m_onStatusMessage = x => { }; m_onProcessException = x => { }; m_globalCache = new GlobalCache(new Dictionary<IAdapter, Consumer>(), 0); RouteCount = m_globalCache.GlobalSignalLookup.Count(x => x != null); }
/// <summary> /// Attempts to disconnect from data input source. /// </summary> protected override void AttemptDisconnection() { if ((object)m_timer != null) { m_timer.Dispose(); m_timer = null; } if ((object)m_statusUpdate != null) { m_statusUpdate.Dispose(); m_statusUpdate = null; } }
/// <summary> /// Releases the unmanaged resources used by the <see cref="MovingValueInputAdapter"/> object and optionally releases the managed resources. /// </summary> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (!m_disposed) { try { if (disposing) { if ((object)m_timer != null) { m_timer.Dispose(); m_timer = null; } } } finally { m_disposed = true; // Prevent duplicate dispose. base.Dispose(disposing); // Call base class Dispose(). } } }
public UpdateFramework() { m_refreshInterval = new TimeSpan(1 * TimeSpan.TicksPerSecond); m_playback = new AutomaticPlayback(); m_enabled = true; m_syncEvent = new SynchronousEvent<QueryResultsEventArgs>(); m_syncEvent.CustomEvent += m_syncEvent_CustomEvent; m_async = new ScheduledTask(ThreadingMode.DedicatedForeground); m_async.Running += AsyncDoWork; m_async.UnhandledException += OnError; m_activeSignals = new List<MetadataBase>(); m_syncRoot = new object(); }