/// <summary> /// Выполняет принудительный вызов процедуры обработки поступивших данных /// </summary> /// <param name="sender">Источник события</param> /// <param name="e">Параметры события</param> public void SerialStaticEventHandler(object sender, EventArgs e) { if (async == null) { async = sync_call.BeginInvoke(null, null, null); } else { if (async.IsCompleted) { async = sync_call.BeginInvoke(null, null, null); } } }
private void TimerThreadCallback(TimerCallback timerCallback) { ThreadStart threadStart = new ThreadStart(() => { Thread.Sleep(_Period); lock (_Lock) { if (_IsRunning) {// we have to check whether we are still running, otherwise we might end up sending this signal for a new thread start Monitor.Pulse(_Lock); } } }); lock (_Lock) { while (_IsRunning) { if (_PreciseTimerCallbackMode == PreciseTimerCallbackMode.Synchronized) { timerCallback.Invoke(null); } else { timerCallback.BeginInvoke(null, null, null); } threadStart.BeginInvoke(null, null); Monitor.Wait(_Lock); } } }
/// <summary> /// Обработать сообщение конвертера о завершении преобразования поступивших данных /// </summary> /// <param name="sender">Источник события</param> /// <param name="e">Параметры события</param> public void OnCompleteConverter(object sender, EventArgs e) { if (async == null) { Interlocked.Increment(ref counter); async = sync_call.BeginInvoke(null, null, null); } else { if (async.IsCompleted) { Interlocked.Increment(ref counter); async = sync_call.BeginInvoke(null, null, null); } } }
/// <summary> /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed. /// <example> /// timercallback.BeginInvoke(state, callback); /// </example> /// </summary> public static IAsyncResult BeginInvoke(this TimerCallback timercallback, Object state, AsyncCallback callback) { if (timercallback == null) { throw new ArgumentNullException("timercallback"); } return(timercallback.BeginInvoke(state, callback, null)); }