当前位置: 首页>>代码示例>>C#>>正文


C# Timer.Stop方法代码示例

本文整理汇总了C#中Timer.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# Timer.Stop方法的具体用法?C# Timer.Stop怎么用?C# Timer.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Timer的用法示例。


在下文中一共展示了Timer.Stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        public static void Main(string[] args)
        {
            int tickCount = 0;
            //sample callback which does the work you want.
            Action callback = () => { tickCount++; };

            // perform work after a specfic interval
            TimeSpan interval = TimeSpan.FromMilliseconds(1);

            //instatiate the timer
            var timer = new Timer(callback, interval);

            //start it
            timer.Start();

            //wait and give some room for processing
            Thread.Sleep(20);

            timer.Stop();
            timer.Dispose();

            //tick count should be ~20-23
            Console.WriteLine("Tick Count => {0}", tickCount);

            // keep result window open to see the result
            Thread.Sleep(2000);
        }
开发者ID:cabhishek,项目名称:Timer,代码行数:27,代码来源:Program.cs

示例2: Delay

        public void Delay()
        {
            //delay to test (3 seconds)
            var delay = new TimeSpan(0, 0, 0, 3 /* seconds */);
            //tollerance (actual time should be between 2.9 and 3.1 seconds)
            var tollerance = new TimeSpan(0, 0, 0, 0, 100 /* milliseconds */);

            Stopwatch stopwatch = new Stopwatch();
            Timer timer = new Timer();

            Loop.Current.QueueWork(() => {
                stopwatch.Start();
                timer.Start(delay, TimeSpan.Zero, () =>
                {
                    stopwatch.Stop();
                    timer.Stop();
                    timer.Close();
                });
            });

            Loop.Current.Run();

            Assert.GreaterOrEqual(stopwatch.Elapsed, delay.Subtract(tollerance));
            Assert.Less(stopwatch.Elapsed, delay.Add(tollerance));
        }
开发者ID:gigi81,项目名称:sharpuv,代码行数:25,代码来源:TimerTests.cs

示例3: Main

 static void Main()
 {
     Timer t = new Timer(500, delegate() { Console.Beep(); Console.WriteLine("Beep"); ; });
     t.Start();
     Thread.Sleep(10000);
     t.Stop();
 }
开发者ID:kreato,项目名称:TelerikAcademyHomeworks,代码行数:7,代码来源:TimerMain.cs

示例4: Main

        // Ima malak bug tuka. Sled kato se spre parviq timer asinhronnata zaqvka prodaljava oshte malko.
        // Ako ima nqkoy jelanie da si poigrae da nameri kak se spira vednaha.
        // Tarsih v neta... no ne mi se zanimava poveche po tova da otdelqm vreme.
        // Taka ili inache e poveche ot iskanoto ot zadachata a i nikoy nqma da polzva tozi taimer sled kato ima gotov :)
        static void Main(string[] args)
        {
            // Create a timer with a ten second interval.
            Timer t = new Timer(10000);
            // Set the Interval to 2 seconds (2000 milliseconds).
            t.Interval = 2000;
            t.ExecuteCommand = TestTimer;
            t.Start();

            //add a work in main thread to be sure the timer work in a second thread and not block this.
            for (int i = 0; i < 55; i++)
            {
                Thread.Sleep(100);
                Console.WriteLine(i);
                if(i == 44) // if we hit number 44 time will stop to print the existing date. But main thread will continue to work
                    t.Stop();
            }

            //add event
            t.Elapsed += t_Elapsed;
            t.StartEvent(); //run the event
            for (int i = 0; i < 155; i++)
            {
                Thread.Sleep(100);
                Console.WriteLine(i);
            }
        }
开发者ID:smihaylovit,项目名称:TelerikAkademy,代码行数:31,代码来源:Program.cs

示例5: TestToplevel

	void TestToplevel ()
	{
		Timer timer = new Timer ();

		Console.Write ("toplevel test 1:");

		TortureMdiChild child = new TortureMdiChild ();
		Button b = new Button ();
		b.Text = "Click me if you see me";
		b.Click += delegate (object sender, EventArgs e) { Console.WriteLine ("PASS"); timer.Stop (); child.Close(); };
		b.Dock = DockStyle.Fill;
		child.ClientSize = new Size (100, 50);
		child.Controls.Add (b);

		timer.Interval = 5000;
		timer.Tick += delegate (object sender, EventArgs e) { Console.WriteLine ("FAIL (timer)"); timer.Stop (); child.Close(); };
		timer.Start ();

		child.ShowDialog (this);
	}
开发者ID:hitswa,项目名称:winforms,代码行数:20,代码来源:test.cs

示例6: Timer_Stop_Test

        public void Timer_Stop_Test()
        {
            var timer = new Timer();
            timer.Start();
            Sys.Thread.Sleep(20);
            Assert.AreNotEqual(0, timer.Elapsed);

            timer.Stop(false);
            Assert.AreNotEqual(0, timer.Elapsed);

            timer.Start(false);
            Assert.AreNotEqual(0, timer.Elapsed);

            timer.Stop(true);
            Assert.AreEqual(0, timer.Elapsed);

            // Start again
            timer.Start();
            Sys.Thread.Sleep(10);
            timer.Start(true);
            Assert.AreEqual(0, timer.Elapsed);
        }
开发者ID:HaKDMoDz,项目名称:Irelia,代码行数:22,代码来源:TimerTest.cs

示例7: TestTimerGet

        public void TestTimerGet()
        {
            Timer timer = new Timer();
            timer.Reset();
            timer.Start();
            Timer.Delay(.3);
            timer.Stop();
            Assert.That(timer.HasPeriodPassed(0.25));
            Assert.That(!timer.HasPeriodPassed(0.55));
            Assert.That(timer.Get, Is.EqualTo(0.3).Within(0.05));

            Timer.Delay(0.3);
            Assert.That(timer.HasPeriodPassed(0.25));
            Assert.That(!timer.HasPeriodPassed(0.55));
            Assert.That(timer.Get, Is.EqualTo(0.3).Within(0.05));
        }
开发者ID:chopshop-166,项目名称:WPILib,代码行数:16,代码来源:TestWPITimer.cs

示例8: NeedRestream

 public override bool NeedRestream()
 {
     if (gameReference.Health == 0 && !will_respawn)
     {
         will_respawn = true;
         var timer = new Timer(6000);
         timer.Tick += (o, e) =>
         {
             position = spawn_position;
             orientation = spawn_orientation;
             if (IsStreamedIn()) StreamOut();
             timer.Stop();
         };
         timer.Start();
     }
     return false;
 }
开发者ID:andrefsantos,项目名称:gta-iv-multiplayer,代码行数:17,代码来源:VehicleStreamer.cs

示例9: StartVisibility

 void StartVisibility()
 {
     this.Top += 15;
     Timer tmr = new Timer();
     tmr.Interval = 50;
     tmr.Tick += (o, e) =>
     {
         if (this.Opacity < 1)
         {
             this.Opacity += 0.2;
             this.Top -= 5;
         }
         else
         {
             this.Opacity = 1;
             tmr.Stop();
         }
     };
     tmr.Start();
 }
开发者ID:EgyFalseX-EESoft-WinForm,项目名称:RetirementCenter,代码行数:20,代码来源:msgDlg.cs

示例10: Client

 public Client()
 {
     var startup = new Timer(6000);
     startup.Tick += (o, e) =>
     {
         startup.Stop();
         BindConsoleCommand("reconnect", (a) =>
         {
             if (System.IO.File.Exists("miv_lastserver.ini"))
             {
                 darkscreen = new ClientRectangleView(new System.Drawing.RectangleF(0, 0, 2000, 2000), System.Drawing.Color.Black);
                 Game.FadeScreenOut(1);
                 string[] lines = System.IO.File.ReadAllLines("miv_lastserver.ini");
                 INIReader reader = new INIReader(lines);
                 initAndConnect(reader.getString("ip"), reader.getInt16("port"), reader.getString("nickname"));
             }
         });
         if (System.IO.File.Exists("_serverinit.ini"))
         {
             darkscreen = new ClientRectangleView(new System.Drawing.RectangleF(0, 0, 2000, 2000), System.Drawing.Color.Black);
             string[] lines = System.IO.File.ReadAllLines("_serverinit.ini");
             INIReader reader = new INIReader(lines);
             Int64 timestamp_saved = reader.getInt64("timestamp");
             Int64 timestamp_now = System.Diagnostics.Stopwatch.GetTimestamp();
             TimeSpan time_delta = new TimeSpan(timestamp_now - timestamp_saved);
             if (time_delta.Minutes < 5)
             {
                 System.IO.File.Delete("_serverinit.ini");
                 System.IO.File.WriteAllLines("miv_lastserver.ini", lines);
                 initAndConnect(reader.getString("ip"), reader.getInt16("port"), reader.getString("nickname"));
             }
         }
         else
         {
             FileSystemOverlay.crashIfSPPreparationFail();
         }
     };
     startup.Start();
     // nope? nothing to do
 }
开发者ID:andrefsantos,项目名称:gta-iv-multiplayer,代码行数:40,代码来源:Client.cs

示例11: DataGridViewProgressCell

        public DataGridViewProgressCell()
        {
            _progressBar = new ProgressBar()
            {
                Minimum = 0,
                Maximum = 100,
                Style = ProgressBarStyle.Continuous
            };

            _text = String.Format("{0} of {1}", MessageSpecialValue.CurrentValue, MessageSpecialValue.Maximum);

            ValueType = typeof(int);

            // repaint every 25 milliseconds while progress is active
            _animationStepTimer = new Timer { Interval = 25, Enabled = true };

            // stop repainting 3 seconds after progress becomes inactive
            _animationStopTimer = new Timer { Interval = 3000, Enabled = false };

            _animationStepTimer.Tick += (x, y) => { stopAnimation(); refresh(); };
            _animationStopTimer.Tick += (x, y) => { _animationStepTimer.Stop(); _animationStopTimer.Stop(); };
        }
开发者ID:AlexandreBurel,项目名称:pwiz-mzdb,代码行数:22,代码来源:DataGridViewProgressBar.cs

示例12: Main

    static void Main()
    {
        Timer timer = new Timer();
        timer.Interval = 1000;
        timer.Tick += timer_Tick;

        //call timer_Tick every second
        timer.Start();

        while (true)
        {
            Console.Write("Enter timer interval [-1 to stop]: ");
            int newInterval = int.Parse(Console.ReadLine());
            if (newInterval == -1)
            {
                timer.Stop();
                break;
            }
            else
            {
                timer.Interval = newInterval;
            }
        }
    }
开发者ID:andon-andonov,项目名称:TelerikAcademy,代码行数:24,代码来源:TestApp.cs

示例13: CreateNotification

        public void CreateNotification(ICollection<Inline> title, ICollection<Inline> message, Color color, TimeSpan showTime)
        {
            var notification = new NotificationView(new NotificationViewModel()
            {
                Title = title,
                Message = message,
                BarBrush = App.GetBrush(color),
            });
            notifications.Add(notification);

            notification.Show();
            PlaceNotification(notification);

            var timer = new Timer(showTime.TotalMilliseconds);
            timer.Elapsed += (sender, e) =>
            {
                timer.Stop();
                timer.Dispose();
                timers.Remove(timer);

                notification.Dispatcher.BeginInvoke(new Action(() =>
                {
                    notification.Close();
                    notifications.Remove(notification);
                }));
            };
            timers.Add(timer);
            timer.Start();
        }
开发者ID:npcook,项目名称:infinichat-client,代码行数:29,代码来源:NotificationManager.cs

示例14: remove

 public bool remove(Timer timer)
 {
     if (list.Contains(timer))
     {
         log.debug("remove, type="
             + getTimerMap(timer, "type")
             + ", interval=" + timer.Interval + " ms");
         log.debug("remove, map={" + getMapToString(timer) + "}");
         list.Remove(timer);
         TagMap.Remove(timer);
         timer.Stop();
         //updateDisplay();
         return true;
     }
     return false;
 }
开发者ID:pipseq,项目名称:csFxModel,代码行数:16,代码来源:TimerMgr.cs

示例15: stop

 public bool stop(Timer timer)
 {
     timer.Stop();
     return remove(timer);
 }
开发者ID:pipseq,项目名称:csFxModel,代码行数:5,代码来源:TimerMgr.cs


注:本文中的Timer.Stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。