Esempio n. 1
0
        public void TestAdd()
        {
            // null function is not allowed
            Assert.That(() => Timeout.Add(0, null),
                        Throws.InstanceOf <ArgumentNullException> ());

            // Timeout.Add() can only attach sources to the global main context,
            // so we need lock to ensure we have exclusive use.
            lock (MainContextTests.MainContextLock) {
                var timeoutInvoked = false;
                var mainLoop       = new MainLoop();

                var id = Timeout.Add(0, () => {
                    mainLoop.Quit();
                    timeoutInvoked = true;
                    return(Source.Remove_);
                });

                Assert.That(id, Is.Not.EqualTo(0));

                var source = MainContext.Default.FindSourceById(id);
                Task.Run(() => {
                    mainLoop.Run();
                }).Wait(100);
                source.Destroy();

                Assert.That(timeoutInvoked, Is.True);
            }

            Utility.AssertNoGLibLog();
        }
Esempio n. 2
0
 public void Start()
 {
     if (!working)
     {
         Timeout.Add(Time, handler);
         working = true;
     }
 }
        protected override async Task <object> ExecuteAsync(CancellationToken cancellationToken)
        {
            //the cancellation token should be none here so it shouldn't throw if we go over the timeout
            var delay = Timeout.Add(TimeSpan.FromMilliseconds(100));

            return(await Task.Run(() =>
            {
                Thread.Sleep(delay);
                cancellationToken.ThrowIfCancellationRequested();
                return 1;
            }, cancellationToken));
        }
Esempio n. 4
0
        protected override async Task <object> ExecuteAsync(CancellationToken cancellationToken)
        {
            // Sleep for 100ms more than the timeout allows.
            var delay = Timeout.Add(TimeSpan.FromMilliseconds(100));

            return(await Task.Run(() =>
            {
                Thread.Sleep(delay);
                cancellationToken.ThrowIfCancellationRequested();
                return 1;
            }, cancellationToken));
        }
Esempio n. 5
0
 public static void BeginInvoke(Action action)
 {
     if (action == null)
     {
         throw new ArgumentNullException("action");
     }
     int num = (int)Timeout.Add(500U, (TimeoutHandler)(() =>
     {
         action();
         return(false);
     }));
 }
Esempio n. 6
0
        public IDisposable Schedule <TState>(TState state, TimeSpan dueTime, Func <IScheduler, TState, IDisposable> action)
        {
            bool isCancelled = false;

            Timeout.Add((uint)dueTime.TotalMilliseconds, () => {
                if (!isCancelled)
                {
                    action(this, state);
                }
                return(false);
            });

            return(Disposable.Create(() => isCancelled = true));
        }
Esempio n. 7
0
 public FoldingScreenbackgroundRenderer(TextEditor editor, IEnumerable <FoldSegment> foldSegments)
 {
     this.editor       = editor;
     this.foldSegments = new List <FoldSegment>(foldSegments);
     startTime         = DateTime.Now;
     timeout           = Timeout.Add(30, delegate
     {
         editor.QueueDraw();
         var cont = (DateTime.Now - startTime).TotalMilliseconds < animationLength;
         if (!cont)
         {
             timeout = null;
         }
         return(cont);
     });
 }
Esempio n. 8
0
        public void TesTimer()
        {
            bool ret   = false;
            var  timer = Timeout.Add(100, (id) => ret = true, (id) => Assert.Fail());
            var  rc    = Thread.Wait(() => ret, 1000);

            Assert.IsTrue(rc);
            Assert.IsTrue(ret);
            rc = Timeout.Remove(timer);
            Assert.IsFalse(rc);

            ret   = false;
            timer = Timeout.Add(1000, (id) => Assert.Fail(), (id) => ret = true);
            Thread.Sleep(10);
            rc = Timeout.Remove(timer);
            Assert.IsTrue(rc);
            Assert.IsTrue(ret);
        }
        static void init_toolbar(HBox toolbar)
        {
            Button button;

            button          = new Button("Monitor");
            button.Clicked += (s, e) =>
            {
                Button button = (Button)(s);
                ChatForm.show_chat_form();
                button.Label = (button.Label == "Monitor") ? "Monitoring" : "Monitor";
            };
            button.SetSizeRequest(128, 128);
            toolbar.PackStart(button, false, false, 0);
            ////////////////////////////////////////////////////////////////////////////
            button          = new Button("Lock");
            button.Clicked += (s, e) =>
            {
                Button button = (Button)(s);
                if (Configure.GetInstance().IsServer == 0)
                {
                    TcpChatClient.Program.chatClient.SendAsync("Hello World!");
                }
                button.Label = (button.Label == "Lock") ? "UnLock" : "Lock";
            };
            button.SetSizeRequest(128, 128);
            toolbar.PackStart(button, false, false, 0);
            ////////////////////////////////////////////////////////////////////////////
            button          = new Button("StartSend");
            button.Clicked += (s, e) =>
            {
                Button button = (Button)(s);
                switch (button.Label)
                {
                case "StartSend":
                {
                    timeScreenshotId = Timeout.Add(timeScreenshot, timeout_screenshot_handler);
                    button.Label     = "StopSend";
                }
                break;

                case "StopSend":
                {
                    Timeout.Remove(timeScreenshotId);
                    button.Label = "StartSend";
                }
                break;

                default:
                {
                    Timeout.Remove(timeScreenshotId);
                    button.Label = "StartSend";
                }
                break;
                }
            };
            button.SetSizeRequest(128, 128);
            toolbar.PackStart(button, false, false, 0);
            ////////////////////////////////////////////////////////////////////////////
            button          = new Button("StartRecv");
            button.Clicked += (s, e) =>
            {
                Button button = (Button)(s);
                switch (button.Label)
                {
                case "StartRecv":
                {
                    timeUpdateshowId = Timeout.Add(timeUpdateshow, timeout_updateshow_handler);
                    button.Label     = "StopRecv";
                }
                break;

                case "StopRecv":
                {
                    Timeout.Remove(timeUpdateshowId);
                    button.Label = "StartRecv";
                }
                break;

                default:
                {
                    Timeout.Remove(timeUpdateshowId);
                    button.Label = "StartRecv";
                }
                break;
                }
            };
            button.SetSizeRequest(128, 128);
            toolbar.PackStart(button, false, false, 0);
        }