コード例 #1
0
        public static RunTask Start(Action action, int delay)
        {
            var run = new RunTask();
            var task = Task.Delay(delay, run.GetToken());
            task.ContinueWith(t =>
            {
                try
                {
                    run.GetToken().ThrowIfCancellationRequested();
                    action();
                }
                catch (Exception)
                {
                }
            });

            return run;
        }
コード例 #2
0
        public static RunTask Start(Action action, int delay)
        {
            var run  = new RunTask();
            var task = Task.Delay(delay, run.GetToken());

            task.ContinueWith(t =>
            {
                try
                {
                    run.GetToken().ThrowIfCancellationRequested();
                    action();
                }
                catch (Exception)
                {
                }
            });

            return(run);
        }
コード例 #3
0
ファイル: Connection.cs プロジェクト: anakiou/IEC-60870
        private void ScheduleMaxTimeNoTestConReceivedFuture()
        {
            if (maxTimeNoTestConReceivedFuture != null)
            {
                maxTimeNoTestConReceivedFuture.Cancel();
                maxTimeNoTestConReceivedFuture = null;
            }

            maxTimeNoTestConReceivedFuture = PeriodicTaskFactory.Start(() =>
            {
                Close();
                ConnectionClosed?.Invoke(new IOException(
                    "The maximum time that no test frame confirmation was received (t1) has been exceeded. t1 = "
                    + settings.MaxTimeNoAckReceived + "ms"));
            }, settings.MaxTimeNoAckReceived);
        }
コード例 #4
0
ファイル: Connection.cs プロジェクト: anakiou/IEC-60870
        private void ResetMaxIdleTimeTimer()
        {
            if (maxIdleTimeTimerFuture != null)
            {
                maxIdleTimeTimerFuture.Cancel();
                maxIdleTimeTimerFuture = null;
            }

            maxIdleTimeTimerFuture = PeriodicTaskFactory.Start(() =>
            {
                try
                {
                    writer.Write(TestfrActBuffer, 0, TestfrActBuffer.Length);
                    writer.Flush();
                }
                catch (Exception)
                {
                    // ignored
                }
                ScheduleMaxTimeNoTestConReceivedFuture();
            }, settings.MaxIdleTime);
        }
コード例 #5
0
ファイル: Connection.cs プロジェクト: anakiou/IEC-60870
        public void Send(ASdu aSdu)
        {
            acknowledgedReceiveSequenceNumber = receiveSequenceNumber;
            var requestAPdu = new APdu(sendSequenceNumber, receiveSequenceNumber, APdu.ApciType.FORMAT, aSdu);
            sendSequenceNumber = (sendSequenceNumber + 1)%32768;

            if (maxTimeNoAckSentFuture != null)
            {
                maxTimeNoAckSentFuture.Cancel();
                maxTimeNoAckSentFuture = null;
            }

            if (maxTimeNoAckReceivedFuture == null)
            {
                ScheduleMaxTimeNoAckReceivedFuture();
            }

            var length = requestAPdu.Encode(buffer, settings);
            writer.Write(buffer, 0, length);
            writer.Flush();

            ResetMaxIdleTimeTimer();
        }