Example #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;
        }
Example #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);
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        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();
        }