本文整理汇总了C#中System.Windows.Forms.Timer.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Timer.Dispose方法的具体用法?C# Timer.Dispose怎么用?C# Timer.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Timer
的用法示例。
在下文中一共展示了Timer.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CallLater
public static void CallLater(TimeSpan delay, Action method)
{
var delayMilliseconds = (int) delay.TotalMilliseconds;
if (delayMilliseconds < 0)
{
throw new ArgumentOutOfRangeException("delay", delay, Properties.Resources.ValueMustBePositive);
}
if (method == null)
{
throw new ArgumentNullException("method");
}
SafeThreadAsyncCall(delegate
{
var t = new Timer
{
Interval = Math.Max(1, delayMilliseconds)
};
t.Tick += delegate
{
t.Stop();
t.Dispose();
method();
};
t.Start();
});
}
示例2: Run
internal bool Run()
{
bool flag;
if (this._insideModalLoop)
{
throw new InvalidOperationException(Microsoft.ManagementConsole.Internal.Utility.LoadResourceString(Microsoft.ManagementConsole.Internal.Strings.ExceptionInternalConsoleDialogHostAlreadyInsideModalLoop));
}
Timer timer = new Timer();
try
{
Application.UseWaitCursor = true;
this._insideModalLoop = true;
timer.Tick += new EventHandler(this.OnTimer);
timer.Interval = (int) this.Timeout.TotalMilliseconds;
timer.Start();
this.InnerStart();
ModalLoop.Run();
flag = !this._timedOut;
}
finally
{
timer.Dispose();
this._timedOut = false;
this._quitMessagePosted = false;
this._insideModalLoop = false;
Application.UseWaitCursor = false;
}
return flag;
}
示例3: LoadShader
private void LoadShader(string fileName)
{
try
{
var log = visualContext.AddUpdateFragmentShader(fileName);
var correctedLineEndings = log.Replace("\n", Environment.NewLine).Trim();
CallOnChange("Loading '+" + fileName + "' with success!" + Environment.NewLine + correctedLineEndings);
}
catch (ShaderLoadException e)
{
var correctedLineEndings = e.Message.Replace("\n", Environment.NewLine);
CallOnChange("Error while compiling shader '" + fileName + "'" + Environment.NewLine + correctedLineEndings);
}
catch (FileNotFoundException e)
{
CallOnChange(e.Message);
}
catch (Exception e)
{
//try reload in 2 seconds, because sometimes file system is still busy
Timer timer = new Timer(); //todo: is this executed on main thread?
timer.Interval = 2000;
timer.Tick += (a, b) =>
{
timer.Stop();
timer.Dispose();
LoadShader(shaderFileName); //if fileName is used here timer will always access fileName of first call and not a potential new one
};
timer.Start();
CallOnChange("Error while accessing shaderfile '" + fileName + "'! Will retry shortly..." + Environment.NewLine + e.Message);
}
}
示例4: AddToUI
private Control[] AddToUI(Host host)
{
var siteLabel = new Label() {
AutoSize = true,
Dock = DockStyle.Fill,
TabIndex = 1,
Text = host.HOST,
TextAlign = System.Drawing.ContentAlignment.MiddleCenter
};
var timeLabel = new Label() {
AutoSize = true,
Dock = DockStyle.Fill,
TabIndex = 2,
TextAlign = System.Drawing.ContentAlignment.MiddleCenter
};
var removeButton = new Button() {
Dock = DockStyle.Fill,
TabIndex = 3,
Text = "remove",
UseVisualStyleBackColor = true
};
if (host.END_TIME.HasValue) {
timeLabel.Text = host.END_TIME.ToString();
var t = new Timer() {
Enabled = true,
Interval = 1000
};
t.Tick += (sender, e) => {
if ((host.END_TIME.Value - DateTime.Now).TotalSeconds > 0) {
timeLabel.Text = TimeSpan.Parse(timeLabel.Text).Subtract(new TimeSpan(0, 0, 1)).ToString();
t.Dispose();
}
else {
host.Unblock();
}
};
removeButton.Click += (sender, e) => {
host.Unblock();
};
} else {
timeLabel.Text = "routed to " + host.REDIRECT;
removeButton.Click += (sender, e) => {
host.Unblock();
};
}
MainTablePanel.RowCount++;
MainTablePanel.RowStyles.Add(new RowStyle());
MainTablePanel.Controls.Add(siteLabel, 0, -1);
MainTablePanel.Controls.Add(timeLabel, 1, -1);
MainTablePanel.Controls.Add(removeButton, 2, -1);
return new Control[] { siteLabel, timeLabel, removeButton };
}
示例5: Bomb
public Bomb(int x, int y)
{
base.X = x;
base.Y = y;
t = new Timer();
t.Interval = Settings.BOMB_DURATION;
t.Tick += (o, e) => { t.Stop(); t.Dispose(); Alive = false; };
t.Start();
}
示例6: Main
public static void Main()
{
try
{
Settings.Configurate();
//database = new Database();
felhasználó = null;
database = new Database();
LoginForm loginform = new LoginForm();
Application.Run(loginform);
database = new Database();
if (loginform.felhasználó != null)
{
felhasználó = loginform.felhasználó;
loginform.Dispose();
refresher = new Timer();
refresher.Interval = Settings.ui_refresh * 1000;
refresher.Tick += Refresher_Elapsed;
refresher.Start();
MainForm mainform = new MainForm();
Application.Run(mainform);
refresher.Dispose();
mainform.Dispose();
}
}
catch (Exception _e)
{
MessageBox.Show("Kezeletlen globális hiba a program futása során!\nKérem jelezze a hibát a rendszergazdának!\nHiba adatai:\n" + _e.Message, "Hiba", MessageBoxButtons.OK, MessageBoxIcon.Error);
string file_name = string.Format("crash-{0:yyyy-MM-dd_hh-mm-ss}.data", DateTime.Now);
try
{
StreamWriter file = new StreamWriter(file_name);
file.WriteLine("Message:\t" + _e.Message);
file.WriteLine("Source:\t" + _e.Source);
file.WriteLine("Data:\t" + _e.Data);
file.WriteLine("Stack:\t" + _e.StackTrace);
file.Close();
}
catch (Exception _ex)
{
MessageBox.Show("További hiba a kivétel mentésekor!\n" + _ex.Message, "Hiba", MessageBoxButtons.OK, MessageBoxIcon.Error);
Environment.Exit(1);
}
MessageBox.Show("A hiba adatait a " + file_name + " nevű file tartalmazza!", "Hiba adatainak elérése", MessageBoxButtons.OK, MessageBoxIcon.Information);
Environment.Exit(0);
}
}
示例7: Delay
/// <summary>
///
/// </summary>
/// <param name="milliseconds"></param>
/// <param name="action"></param>
public static void Delay(int milliseconds, Action action)
{
Timer timer = new Timer();
timer.Interval = milliseconds;
timer.Tick += (object sender, EventArgs e) =>
{
action.Invoke();
timer.Stop();
timer.Dispose();
};
timer.Start();
}
示例8: btnAddCurrentProcess_Click
private void btnAddCurrentProcess_Click(object sender, System.EventArgs e)
{
MessageBox.Show("After you click OK, you have 3 seconds to select the process", "Select process",
MessageBoxButtons.OK, MessageBoxIcon.Information);
Timer lvSelectProcessTimer = new Timer();
lvSelectProcessTimer.Tick += delegate
{
tbxTitle.Text = NativeWin32.GetActiveProcessWindow().Title;
lvSelectProcessTimer.Stop();
lvSelectProcessTimer.Dispose();
};
lvSelectProcessTimer.Interval = 3000;
lvSelectProcessTimer.Start();
}
示例9: Dispose
public void Dispose()
{
if (this._top != 0)
{
int retries = 0;
Timer tmr = new Timer {
Interval = 1,
Enabled = true
};
tmr.Tick += delegate (object sender, EventArgs e) {
if (++retries > 2)
{
tmr.Dispose();
}
try
{
object domDocument = this._browser.Document.DomDocument;
object target = domDocument.GetType().InvokeMember("documentElement", BindingFlags.GetProperty, null, domDocument, null);
int height = this._top;
if (height == -1)
{
HtmlElement body = this._browser.Document.Body;
if (body == null)
{
return;
}
height = body.ScrollRectangle.Height;
}
target.GetType().InvokeMember("scrollTop", BindingFlags.SetProperty, null, target, new object[] { height });
tmr.Dispose();
}
catch
{
}
};
}
}
示例10: ShowWithTimeout
public static DialogResult ShowWithTimeout(this Form form, TimeSpan timeout)
{
form.TopMost = true;
form.AutoSize = true;
var timoutTimer = new Timer
{
Interval = (int)timeout.TotalMilliseconds,
Enabled = true
};
form.Disposed += delegate { timoutTimer.Dispose(); };
timoutTimer.Tick += delegate
{
form.DialogResult = DialogResult.Abort;
form.Close();
Console.WriteLine("timed out");
};
return form.ShowDialog();
}
示例11: SpringScanner_RetryGetResourceInfo
public static void SpringScanner_RetryGetResourceInfo(object sender, ZkData.CancelEventArgs<ZkData.SpringScanner.CacheItem> e)
{
if (thisInstance != null)
thisInstance.Dispose();
if (rememberedResult != null)
{
e.Cancel = rememberedResult=="cancel";
return;
}
thisInstance = new PromptForm();
countDown = new Timer();
countDown.Tick += (s, e1) => {
counter++;
thisInstance.noButton.Text = "No (" + (30 - counter).ToString() + ")";
if (counter==31)
thisInstance.DialogResult = DialogResult.Cancel;
};
countDown.Interval = 1000;
countDown.Enabled = true;
counter = 0;
thisInstance.FormClosed += (s, e1) => { countDown.Dispose(); };
thisInstance.detailBox.Visible = true;
thisInstance.Text = "New resource found!";
thisInstance.questionText.Text = Environment.NewLine + "Server connection failed. Extract \"" + e.Data.FileName + "\" information manually?";
thisInstance.noButton.Text = "No,Wait";
Program.ToolTip.SetText(thisInstance.okButton, "Perform UnitSync on this file immediately if UnitSync is available");
Program.ToolTip.SetText(thisInstance.noButton, "Reask server for map/mod information after 2 minute");
Program.ToolTip.SetText(thisInstance.rememberChoiceCheckbox, "Remember choice for this session only");
thisInstance.detailText.WordWrap = false;
var detailText = "File name: " + e.Data.FileName + Environment.NewLine;
detailText = detailText + "MD5: " + e.Data.Md5.ToString() + Environment.NewLine;
detailText = detailText + "Internal name: " + e.Data.InternalName + Environment.NewLine;
detailText = detailText + "Recommended action: Restore Connection & Wait";
thisInstance.detailText.Text = detailText;
thisInstance.ShowDialog();
e.Cancel = (thisInstance.DialogResult == DialogResult.OK);
if (thisInstance.rememberChoiceCheckbox.Checked)
rememberedResult = e.Cancel ? "cancel" : "ok";
}
示例12: SpringScanner_UploadUnitsyncData
public static void SpringScanner_UploadUnitsyncData(object sender, ZkData.CancelEventArgs<ZkData.IResourceInfo> e)
{
if (thisInstance != null)
thisInstance.Dispose();
if (rememberedResult != null)
{
e.Cancel = rememberedResult == "cancel";
return;
}
thisInstance = new PromptForm();
countDown = new Timer();
countDown.Tick += (s, e1) => {
counter++;
thisInstance.okButton.Text = "Ok (" + (30 - counter).ToString() + ")";
if (counter == 31)
thisInstance.DialogResult = DialogResult.OK;
};
countDown.Interval = 1000;
countDown.Enabled = true;
counter = 0;
thisInstance.FormClosed += (s, e1) => { countDown.Dispose(); };
thisInstance.detailBox.Visible = true;
thisInstance.Text = "New information extracted!";
thisInstance.questionText.Text = Environment.NewLine + "No server data regarding this file hash. Upload \"" + e.Data.Name + "\" information to server?";
thisInstance.okButton.Text = "Ok,Share";
Program.ToolTip.SetText(thisInstance.okButton, "This map/mod will be listed on both ZKL and Springie");
Program.ToolTip.SetText(thisInstance.noButton, "This map/mod will be listed only on this ZKL");
Program.ToolTip.SetText(thisInstance.rememberChoiceCheckbox, "Remember choice for this session only");
thisInstance.detailText.WordWrap = false;
var detailText = "Resource name: " + e.Data.Name + Environment.NewLine;
detailText = detailText + "Archive name: " + e.Data.ArchiveName + Environment.NewLine;
detailText = detailText + "Recommended action: Share multiplayer resource";
thisInstance.detailText.Text = detailText;
thisInstance.ShowDialog();
e.Cancel = (thisInstance.DialogResult == DialogResult.Cancel);
if (thisInstance.rememberChoiceCheckbox.Checked)
rememberedResult = e.Cancel ? "cancel" : "ok";
}
示例13: SafeSetClipboard
static void SafeSetClipboard(object dataObject)
{
// Work around ExternalException bug. (SD2-426)
// Best reproducable inside Virtual PC.
int version = unchecked(++SafeSetClipboardDataVersion);
try {
Clipboard.SetDataObject(dataObject, true);
} catch (ExternalException) {
Timer timer = new Timer();
timer.Interval = 100;
timer.Tick += delegate {
timer.Stop();
timer.Dispose();
if (SafeSetClipboardDataVersion == version) {
try {
Clipboard.SetDataObject(dataObject, true, 10, 50);
} catch (ExternalException) { }
}
};
timer.Start();
}
}
示例14: Test
public void Test()
{
var close = false;
var form = new Form();
form.Closing += (s, e) => close = true;
var xLabel = new Label { Parent = form };
var yLabel = new Label { Parent = form, Top = 40 };
var zLabel = new Label { Parent = form, Top = 80 };
var inputDevices = new XnaInputDevices();
var keyboard = inputDevices.Keyboard;
keyboard.On(Button.X).IsDown().Do(() => close = true);
keyboard.On(Button.Escape).WasReleased().Do(() => close = true);
keyboard.On(Button.W).WasReleased().Do(() => form.Text = "Pressed");
keyboard.On(Button.S).IsDown().Do(() => form.Text = "Down");
var mouse = inputDevices.Mouse;
mouse.On(Button.LeftMouse).IsDown().Do(() => form.Text = "Left Mouse down");
mouse.On(Button.RightMouse).WasReleased().Do(() => form.Text = "Right Mouse was pressed");
mouse.On(Axis.X).Do(delta => xLabel.Text = "X: " + delta);
mouse.On(Axis.Y).Do(delta => yLabel.Text = "Y: " + delta);
mouse.On(Axis.Z).Do(delta => zLabel.Text = "Z: " + delta);
form.Show();
var timer = new Timer { Interval = 10 };
timer.Tick += (s, e) => inputDevices.Update();
timer.Start();
while (!close)
{
Application.DoEvents();
}
timer.Stop();
timer.Dispose();
}
示例15: SessionThreadStart
void SessionThreadStart()
{
Monitor.Enter(sessionThread);
{
try
{
sessionThreadControl = new Control();
sessionThreadControl.CreateControl();
session = TtlLiveSingleton.Get();
dataTimer = new Timer();
dataTimer.Interval = 100;
dataTimer.Tick += new EventHandler(dataTimer_Tick);
notificationTimer = new Timer();
notificationTimer.Interval = 100;
notificationTimer.Tick += new EventHandler(notificationTimer_Tick);
notificationTimer.Start();
}
catch (Exception ex)
{
sessionThreadInitException = ex;
TtlLiveSingleton.Dispose();
}
Monitor.Pulse(sessionThread);
}
Monitor.Exit(sessionThread);
//Create a message pump for this thread
Application.Run(applicationContext);
//Dispose of all stuff on this thread
dataTimer.Stop();
dataTimer.Dispose();
notificationTimer.Stop();
notificationTimer.Dispose();
TtlLiveSingleton.Dispose();
sessionThreadControl.Dispose();
return;
}