本文整理汇总了C#中System.Timers.Timer.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# System.Timers.Timer.Dispose方法的具体用法?C# System.Timers.Timer.Dispose怎么用?C# System.Timers.Timer.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Timers.Timer
的用法示例。
在下文中一共展示了System.Timers.Timer.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetIntAsync
public static Task<int> GetIntAsync(CancellationToken token = default(CancellationToken))
{
var tcs = new TaskCompletionSource<int>();
if (token.IsCancellationRequested)
{
tcs.SetCanceled();
return tcs.Task;
}
var timer = new System.Timers.Timer(3000);
timer.AutoReset = false;
timer.Elapsed += (s, e) =>
{
tcs.TrySetResult(10);
timer.Dispose();
};
if (token.CanBeCanceled)
{
token.Register(() => {
tcs.TrySetCanceled();
timer.Dispose();
});
}
timer.Start();
return tcs.Task;
}
示例2: Execute
public virtual void Execute() {
if (Running)
throw new InvalidOperationException("Script is already running");
ExecutionTime = TimeSpan.Zero;
Exception ex = null;
var timer = new System.Timers.Timer(250) { AutoReset = true };
timer.Elapsed += timer_Elapsed;
try {
Running = true;
OnScriptExecutionStarted();
lastUpdateTime = DateTime.UtcNow;
timer.Start();
ExecuteCode();
} catch (Exception e) {
ex = e;
} finally {
timer.Elapsed -= timer_Elapsed;
timer.Stop();
timer.Dispose();
ExecutionTime += DateTime.UtcNow - lastUpdateTime;
Running = false;
OnScriptExecutionFinished(ex);
}
}
示例3: Run
public static void Run()
{
System.Timers.Timer tr = new System.Timers.Timer(1000);
tr.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) => { System.Console.WriteLine("kkk"); };
tr.Disposed += (sender, e) => { System.Console.WriteLine("end"); };
tr.Enabled = true;
Thread.Sleep(5000);
tr.Dispose();
}
示例4: RestorePST
public void RestorePST()
{
System.Timers.Timer Clock = new System.Timers.Timer(3000);
Clock.Elapsed += delegate
{
Settings.canuseprintscreen = true;
txtPST.BackColor = SystemColors.Control;
Clock.Dispose();
};
Clock.Start();
}
示例5: TimersTimer
private static void TimersTimer()
{
var t1 = new System.Timers.Timer(1000);
t1.AutoReset = true;
t1.Elapsed += TimeAction;
t1.Start();
Thread.Sleep(10000);
t1.Stop();
t1.Dispose();
}
示例6: CodeCompletionStrategy
protected CodeCompletionStrategy(CodeEditor codeEditor) {
this.codeEditor = codeEditor;
this.codeEditor.TextEditorTextChanged += codeEditor_TextEditorTextChanged;
parserTimer = new Timer(1000);
parserTimer.Elapsed += (sender, args) => Task.Run(() => {
DoParseStep();
if (codeEditor.IsDisposed && parserTimer.Enabled) {
parserTimer.Stop();
parserTimer.Dispose();
}
});
}
示例7: Delay
public static Task Delay(int ms)
{
var tcs = new TaskCompletionSource<object>();
var timer = new System.Timers.Timer(ms) { AutoReset = false };
timer.Elapsed += delegate
{
timer.Dispose();
tcs.SetResult(null);
};
timer.Start();
return tcs.Task;
}
示例8: TaskBasedTimer
static Task TaskBasedTimer(int milliseconds)
{
var deferred = new TaskCompletionSource<object>();
var timer = new System.Timers.Timer(milliseconds);
timer.AutoReset = false;
timer.Elapsed += (sender,eventArgs) => {
deferred.SetResult(null);
timer.Dispose();
};
timer.Start();
return deferred.Task;
}
示例9: GetIntAsync
public static Task<int> GetIntAsync() {
var tcs = new TaskCompletionSource<int>();
var timer = new System.Timers.Timer(2000);
timer.AutoReset = false;
timer.Elapsed += (s, e) => {
tcs.SetResult(10);
timer.Dispose();
};
timer.Start();
return tcs.Task;
}
示例10: DelayExecute
/// <summary>
/// 延迟执行
/// </summary>
/// <param name="delayTime">延迟时间,毫秒</param>
/// <param name="execute">执行函数</param>
public static void DelayExecute(int delayTime, Action execute)
{
var time = new System.Timers.Timer();
time.Interval = delayTime;
time.Elapsed += (s, e) =>
{
time.Enabled = false;
if (execute != null)
{
execute();
}
time.Dispose();
};
time.Enabled = true;
}
示例11: Main
static void Main(string[] args)
{
if (args.Length != 2)
return;
m_targetTime = DateTime.Parse(args[0]);
m_warningTime = TimeSpan.Parse(args[1]);
m_updateSignTextThread = new Thread(new System.Threading.ThreadStart(() =>
{
while (!m_isStopRequested)
{
lock (m_lock)
{
RenderToLedSign(m_signText);
System.Threading.Thread.Sleep(250);
RenderToLedSign(m_signText);
System.Threading.Thread.Sleep(250);
}
if (m_isFlashing)
{
RenderToLedSign(" ");
System.Threading.Thread.Sleep(250);
RenderToLedSign(" ");
System.Threading.Thread.Sleep(250);
}
}
}));
m_updateTimerTextTimer = new SystemTimer();
m_updateTimerTextTimer.Interval = TimeSpan.FromMilliseconds(500).TotalMilliseconds;
m_updateTimerTextTimer.Elapsed += (s, e) => UpdateSignText();
RenderToLedSign("Hello");
System.Threading.Thread.Sleep(5000);
UpdateSignText();
m_updateSignTextThread.Start();
m_updateTimerTextTimer.Start();
Console.WriteLine("Press <Enter> to exit.");
Console.ReadLine();
m_updateTimerTextTimer.Stop();
m_updateTimerTextTimer.Dispose();
m_isStopRequested = true;
}
示例12: TimerAsyncResult
public TimerAsyncResult(string correlationId, int millisecondsToWait, object asyncState, AsyncCallback asyncCallback)
{
this.correlationId = correlationId;
IsCompleted = false;
AsyncState = asyncState;
// mimic a long running operation
var timer = new System.Timers.Timer(millisecondsToWait);
timer.Elapsed += (_, args) =>
{
IsCompleted = true;
asyncCallback(this);
timer.Enabled = false;
timer.Dispose();
};
timer.Enabled = true;
}
示例13: Crawl_Asynchronous_CancellationTokenCancelled_StopsCrawl
public void Crawl_Asynchronous_CancellationTokenCancelled_StopsCrawl()
{
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
System.Timers.Timer timer = new System.Timers.Timer(800);
timer.Elapsed += (o, e) =>
{
cancellationTokenSource.Cancel();
timer.Stop();
timer.Dispose();
};
timer.Start();
PoliteWebCrawler crawler = new PoliteWebCrawler();
Task<CrawlResult> task = Task.Factory.StartNew<CrawlResult>(() => crawler.Crawl(new Uri("http://localhost.fiddler:1111/"), cancellationTokenSource));
CrawlResult result = task.Result;
Assert.IsTrue(result.ErrorOccurred);
Assert.IsTrue(result.ErrorException is OperationCanceledException);
}
示例14: DisplayDelayed
public static void DisplayDelayed(string message, int x, int y, int milliseconds)
{
var index = 0;
var timer = new System.Timers.Timer(milliseconds);
Console.SetCursorPosition(x, y);
timer.Elapsed += delegate
{
if (index < message.Length)
{
Console.Write(message[index]);
index++;
}
else
{
timer.Enabled = false;
timer.Dispose();
}
};
timer.Enabled = true;
}
示例15: UpdateCheck
public static void UpdateCheck(bool wait = false, Player p = null)
{
CurrentUpdate = true;
Thread updateThread = new Thread(new ThreadStart(delegate
{
WebClient Client = new WebClient();
if (wait) { if (!Server.checkUpdates) return; Thread.Sleep(10000); }
try
{
if (Client.DownloadString("http://www.mclawl.tk/curversion.txt") != Server.Version)
{
if (Server.autoupdate == true || p != null)
{
if (Server.autonotify == true || p != null)
{
if (p != null) Server.restartcountdown = "20";
Player.GlobalMessage("Update found. Prepare for restart in &f" + Server.restartcountdown + Server.DefaultColor + " seconds.");
Server.s.Log("Update found. Prepare for restart in " + Server.restartcountdown + " seconds.");
double nxtTime = Convert.ToDouble(Server.restartcountdown);
DateTime nextupdate = DateTime.Now.AddMinutes(nxtTime);
int timeLeft = Convert.ToInt32(Server.restartcountdown);
System.Timers.Timer countDown = new System.Timers.Timer();
countDown.Interval = 1000;
countDown.Start();
countDown.Elapsed += delegate
{
if (Server.autoupdate == true || p != null)
{
Player.GlobalMessage("Updating in &f" + timeLeft + Server.DefaultColor + " seconds.");
Server.s.Log("Updating in " + timeLeft + " seconds.");
timeLeft = timeLeft - 1;
if (timeLeft < 0)
{
Player.GlobalMessage("---UPDATING SERVER---");
Server.s.Log("---UPDATING SERVER---");
countDown.Stop();
countDown.Dispose();
PerformUpdate(false);
}
}
else
{
Player.GlobalMessage("Stopping auto restart.");
Server.s.Log("Stopping auto restart.");
countDown.Stop();
countDown.Dispose();
}
};
}
else
{
PerformUpdate(false);
}
}
else
{
if (!msgOpen && !usingConsole)
{
msgOpen = true;
if (MessageBox.Show("New version found. Would you like to update?", "Update?", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
PerformUpdate(false);
}
msgOpen = false;
}
else
{
ConsoleColor prevColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("An update was found!");
Console.WriteLine("Update using the file at www.mclawl.tk/MCLawl_.dll and placing it over the top of your current MCPink_.dll!");
Console.ForegroundColor = prevColor;
}
}
}
else
{
Player.SendMessage(p, "No update found!");
}
}
catch { Server.s.Log("No web server found to update on."); }
Client.Dispose();
CurrentUpdate = false;
})); updateThread.Start();
}