本文整理汇总了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);
}
示例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));
}
示例3: Main
static void Main()
{
Timer t = new Timer(500, delegate() { Console.Beep(); Console.WriteLine("Beep"); ; });
t.Start();
Thread.Sleep(10000);
t.Stop();
}
示例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);
}
}
示例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);
}
示例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);
}
示例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));
}
示例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;
}
示例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();
}
示例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
}
示例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(); };
}
示例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;
}
}
}
示例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();
}
示例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;
}
示例15: stop
public bool stop(Timer timer)
{
timer.Stop();
return remove(timer);
}