Esempio n. 1
0
        public void StartShouldStartTimer()
        {
            var timer = _timerFactory.Create();

            timer.Start();
            Assert.Greater(timer.Elapsed, TimeSpan.FromMilliseconds(0));
        }
Esempio n. 2
0
        public void Create_WithParams_CreatedTimer()
        {
            var taskFactory = Substitute.For <Func <Task> >();
            var interval    = 1000;

            var result = _timerFactory.Create(taskFactory, interval);

            Assert.NotNull(result);
            Assert.IsType <Timer>(result);
        }
        public TabitTimecodeListener(InputDevice midiIn, int midiChannel)
        {
            MidiIn       = midiIn;
            MidiChannel  = midiChannel;
            NoteReceiver = new NoteTimecodeReceiver();

            Timer        = TimerFactory.Create();
            Timer.Mode   = TimerMode.Periodic;
            Timer.Period = 10;
            Timer.Tick  += Timer_Tick;

            MidiIn.StartRecording();
            MidiIn.ChannelMessageReceived += MidiIn_ChannelMessageReceived;
        }
        public void CreatesTimersThatWork()
        {
            int elapsedCount = 0;

            factory.Create(() => { elapsedCount++; }, 1);
            elapsedCount.Should().Be(0);

            Thread.Sleep(10);
            elapsedCount.Should().Be(0);

            factory.LastCreated.Start();
            Thread.Sleep(10);
            elapsedCount.Should().BeGreaterThan(3);

            factory.LastCreated.Stop();
            int currentElapsedCount = elapsedCount;

            Thread.Sleep(10);
            currentElapsedCount.Should().Be(elapsedCount);
        }
Esempio n. 5
0
        private static void Main(string[] args)
        {
            var program = new Program();

            program.TimerTest(TimerFactory.Create());
            program.TimerTest(new SpinWaitTimer());

            program.TimerEventTest(TimerFactory.Create());
            program.TimerEventTest(new SpinWaitTimer());

            Console.WriteLine("Finished...");

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return;
            }

            Console.WriteLine("Press Enter to quit.");
            Console.ReadLine();
        }
        /// <summary>
        /// Starts sending messages over a web socket
        /// </summary>
        /// <param name="message">The message.</param>
        private void Start(WebSocketMessageInfo message)
        {
            var vals = message.Data.Split(',');

            var dueTimeMs = long.Parse(vals[0], UsCulture);
            var periodMs  = long.Parse(vals[1], UsCulture);

            if (vals.Length > 2)
            {
                ParseMessageParams(vals.Skip(2).ToArray());
            }

            var cancellationTokenSource = new CancellationTokenSource();

            Logger.Debug("{1} Begin transmitting over websocket to {0}", message.Connection.RemoteEndPoint, GetType().Name);

            var timer = SendOnTimer ?
                        TimerFactory.Create(TimerCallback, message.Connection, Timeout.Infinite, Timeout.Infinite) :
                        null;

            var state = new TStateType
            {
                IntervalMs     = periodMs,
                InitialDelayMs = dueTimeMs
            };

            var semaphore = new SemaphoreSlim(1, 1);

            lock (ActiveConnections)
            {
                ActiveConnections.Add(new Tuple <IWebSocketConnection, CancellationTokenSource, ITimer, TStateType, SemaphoreSlim>(message.Connection, cancellationTokenSource, timer, state, semaphore));
            }

            if (timer != null)
            {
                timer.Change(TimeSpan.FromMilliseconds(dueTimeMs), TimeSpan.FromMilliseconds(periodMs));
            }
        }
Esempio n. 7
0
 public MidiInternalClock(int timerPeriod) : base(timerPeriod)
 {
     timer        = TimerFactory.Create();
     timer.Period = timerPeriod;
     timer.Tick  += new EventHandler(HandleTick);
 }
Esempio n. 8
0
 public Fixture()
 {
     TimerFactory.Create(Arg.Any <TimerCallback>()).Returns(Timer);
 }
 public QuarterFrameTimecodeGenerator(OutputDevice outDevice, TimeCode timeCode)
 {
     this.outDevice = outDevice;
     this.timeCode  = timeCode;
     Timer          = TimerFactory.Create();
 }
Esempio n. 10
0
 public void it_should_throw_ArgumentNullException_if_options_parameter_is_null()
 {
     Assert.Throws <ArgumentNullException>(() => _timerFactory.Create(null));
 }