本文整理汇总了C#中System.Windows.Forms.Timer.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# System.Windows.Forms.Timer.Dispose方法的具体用法?C# System.Windows.Forms.Timer.Dispose怎么用?C# System.Windows.Forms.Timer.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Timer
的用法示例。
在下文中一共展示了System.Windows.Forms.Timer.Dispose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DelayExecuteWin
/// <summary>
/// 延迟执行
/// </summary>
/// <param name="delayTime">延迟时间,毫秒</param>
/// <param name="execute">执行函数</param>
public static void DelayExecuteWin(int delayTime, Action execute)
{
var time = new System.Windows.Forms.Timer();
time.Interval = delayTime;
time.Tick += (s, e) =>
{
time.Enabled = false;
if (execute != null)
{
execute();
}
time.Dispose();
};
time.Enabled = true;
}
示例2: Run
/// <summary>
/// Initializes WinForms and starts the message loop. Blocks until <see cref="Terminate"/> is called.
/// </summary>
public void Run()
{
_guiThread = Thread.CurrentThread;
Application.CurrentUICultureChanged += Application_CurrentUICultureChanged;
// this must be called before any GUI objects are created - otherwise we get problems with icons not showing up
System.Windows.Forms.Application.EnableVisualStyles();
// create a timer to raise the Started event from the message pump
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Interval = 100;
timer.Tick += delegate(object sender, EventArgs args)
{
// immediately disable the timer so we don't get a second Tick
timer.Dispose();
EventsHelper.Fire(_started, this, EventArgs.Empty);
};
timer.Enabled = true;
// start the message pump
System.Windows.Forms.Application.Run();
}
示例3: Timeout
public void Timeout(float time, System.Action action)
{
System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
t.Tick += new EventHandler((o, s) => { t.Dispose(); action(); });
t.Interval = (int)(time * 1000);
t.Enabled = true;
}