本文整理汇总了C#中Timer.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Timer.Dispose方法的具体用法?C# Timer.Dispose怎么用?C# Timer.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer
的用法示例。
在下文中一共展示了Timer.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Timer_Change_UInt32_Int64_AfterDispose_Throws
public void Timer_Change_UInt32_Int64_AfterDispose_Throws()
{
var t = new Timer(EmptyTimerTarget);
t.Dispose();
Assert.Throws<ObjectDisposedException>(() => t.Change(0u, 0u));
Assert.Throws<ObjectDisposedException>(() => t.Change(0L, 0L));
}
示例2: Collapse
public void Collapse(bool silent = false)
{
if (silent || AnimationDelay == 0)
{
Width = pnClosed.Width;
pnOpened.Visible = false;
pnClosed.Visible = true;
}
else
{
var timer = new Timer();
timer.Interval = AnimationDelay > ContentSize ? AnimationDelay / ContentSize : 100;
timer.Tick += (o, e) =>
{
if (Width > (pnClosed.Width + 50))
Width -= 50;
else
{
Width = pnClosed.Width;
pnOpened.Visible = false;
pnClosed.Visible = true;
timer.Stop();
timer.Dispose();
timer = null;
}
Application.DoEvents();
};
timer.Start();
}
if (!silent)
StateChanged?.Invoke(this, new StateChangedEventArgs(false));
}
示例3: Main
static void Main()
{
// Create an event to signal the timeout count threshold in the
// timer callback.
AutoResetEvent autoEvent = new AutoResetEvent(false);
StatusChecker statusChecker = new StatusChecker(10);
// Create an inferred delegate that invokes methods for the timer.
TimerCallback tcb = statusChecker.CheckStatus;
// Create a timer that signals the delegate to invoke
// CheckStatus after one second, and every 1/4 second
// thereafter.
Console.WriteLine("{0} Creating timer.\n",
DateTime.Now.ToString("h:mm:ss.fff"));
Timer stateTimer = new Timer(tcb, autoEvent, 1000, 250);
// When autoEvent signals, change the period to every
// 1/2 second.
autoEvent.WaitOne(5000, false);
stateTimer.Change(0, 500);
Console.WriteLine("\nChanging period.\n");
// When autoEvent signals the second time, dispose of
// the timer.
autoEvent.WaitOne(5000, false);
stateTimer.Dispose();
Console.WriteLine("\nDestroying timer.");
}
示例4: ExecutionLoop
protected override void ExecutionLoop(IAsyncResult result)
{
icon = new NotifyIcon();
timer = new Timer();
icons = new Icon[4];
for (int i = 0; i < 4; i++)
{
icons[i] = (Icon) GetResourceObject( (i + 1).ToString());
}
icon.Icon = icons[currentIconIndex];
icon.Text = GetResourceString("IconTip");
icon.Visible = true;
icon.DoubleClick += OnIconDoubleClick;
timer.Tick += OnTimerTick;
timer.Interval = 350;
timer.Start();
Application.Run();
icon.Dispose();
timer.Dispose();
}
示例5: 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);
}
示例6: ShowDataSourceSelector
public override bool ShowDataSourceSelector()
{
Timer t = new Timer();
t.Interval = 5;
t.Tick += (s, e) => { t.Stop(); t.Dispose(); t = null; ShowDataSeriesConfig(); };
t.Start();
return true;
}
示例7: DisposeTest
public async Task DisposeTest()
{
int callCount = 0;
//Run the timer for a second, then change it, and run it for another second to get a total count
//Expect 9 iterations
Timer timer = new Timer((s) => callCount++, null, 100, 100);
await Task.Delay(1000);
//Expect no more iterations
timer.Dispose();
int lastCallCount = callCount;
await Task.Delay(1000);
timer.Dispose();
Assert.AreEqual(lastCallCount, callCount, "Timer continued to fire after being stopped");
}
示例8: FadeOut
void FadeOut()
{
if (InFadeOut)
return;
if (SystemInformation.TerminalServerSession)
{
if (Startup)
Application.ExitThread();
StressForm = null;
base.Close();
return;
}
int duration = 500;//in milliseconds
int steps = 50;
Timer timer = new Timer();
timer.Interval = duration / steps;
timer.Enabled = true;
int currentStep = steps;
timer.Tick += (arg1, arg2) =>
{
Opacity = ((double)currentStep) / steps;
currentStep--;
if (currentStep <= 0)
{
timer.Stop();
timer.Dispose();
if (Startup)
Application.ExitThread();
Visible = false;
if (StressForm != null && StressForm.Visible)
StressForm.Invoke(new Action(() =>
{
if (StressForm != null)
{
StressForm.TopMost = true;
Application.DoEvents();
StressForm.TopMost = false;
}
}));
StressForm = null;
base.Close();
}
};
timer.Start();
}
示例9: BiometricsLogin
public void BiometricsLogin()
{
var context = new LAContext();
NSError AuthError;
var myReason = new NSString(LoginScreenData.BioLoginMessage);
if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError))
{
var replyHandler = new LAContextReplyHandler((success, error) =>
{
this.InvokeOnMainThread(() =>
{
if (success)
{
var obj = Global.DatabaseManager.GetUsername();
var pwd = Encrypt.DecryptString(obj.PWD);
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("username", obj.Username);
parameters.Add("password", pwd);
parameters.Add("app_device_number", Device.DeviceID);
loginScreenView.Hide();
initLoadingScreenView(LoginScreenData.LoadingScreenTextLogin);
atimer = new Timer(1000);
atimer.Elapsed += (s, e) =>
{
if (ServerURLReady)
{
InvokeOnMainThread(() =>
{
LoginWebCall(parameters);
atimer.Stop();
atimer.Dispose();
});
}
};
atimer.AutoReset = true;
atimer.Enabled = true;
}
else if (error!=null && error.ToString().Contains("Application retry limit exceeded")){
//Show fallback mechanism here
new UIAlertView(LoginScreenData.AlertScreenBioLoginFailTitle,
error.ToString()+" "+LoginScreenData.AlertScreenBioLoginFaildMessage,
null, LoginScreenData.AlertScreenBioLoginFaildCancelBtnTitle, null).Show();
}
PWDLogin();
});
});
context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, myReason, replyHandler);
}
else {
loginScreenView.userNameTextField.Hidden = false;
loginScreenView.passwordTextField.Hidden = false;
loginScreenView.loginBtn.Hidden = false;
loginScreenView.fingerPrintView.Hidden = true;
}
}
示例10: InitTimer
private void InitTimer()
{
_timer = new Timer();
_timer.Interval = 1;
_timer.Tick += (o, e) =>
{
SetBrowser();
_timer.Stop();
_timer.Dispose();
};
}
示例11: Main
public static int Main(string[] args)
{
Thread th = new Thread(new ThreadStart(Thread2));
th.Start();
Thread th2 = new Thread(new ThreadStart(Thread3));
th2.Start();
for (int i = 0; i < 20000 && !_fTestFailed; i++)
{
_mre = new ManualResetEvent(false);
Timer t = new Timer(new TimerCallback(callback), null, 1000000, Timeout.Infinite);
_are.Set();
bool bDisposeSucceeded = false; //Used to improve speed of the test when Dispose has failed
try
{
t.Dispose();
bDisposeSucceeded = true;
}
catch (ObjectDisposedException)
{
}
if (bDisposeSucceeded)
{
try
{
if (_mre.WaitOne(0))
{
Console.Write("@");
}
}
catch (ObjectDisposedException)
{
}
}
}
_fTestDone = true;
_are.Set();
th.Join();
th2.Join();
if (!_fTestFailed)
{
Console.WriteLine("Test Passed");
return 100;
}
Console.WriteLine("Test Failed");
return 101;
}
示例12: ShowPopup
public static void ShowPopup(MailScreen parent, string newBlockedUser)
{
Timer timer = new Timer {
Interval = 30
};
timer.Tick += new EventHandler(MailUserBlockPopup.tooltipCallbackFunction);
timer.Tag = "0";
timer.Enabled = true;
MailUserBlockPopup popup = new MailUserBlockPopup();
popup.init(parent, newBlockedUser);
popup.ShowDialog(InterfaceMgr.Instance.ParentForm);
popup.Dispose();
timer.Stop();
timer.Dispose();
}
示例13: ChangeTest
public async Task ChangeTest()
{
int callCount = 0;
//Run the timer for a second, then change it, and run it for another second to get a total count
//Expect 9 iterations
Timer timer = new Timer((s) => callCount++, null, 100, 100);
await Task.Delay(1000);
//Expect 4 iterations
timer.Change(200, 200);
await Task.Delay(1000);
timer.Dispose();
Assert.AreEqual(13, callCount, "Callcount was incorrect");
}
示例14: RefreshGrid2
public void RefreshGrid2()
{
///
/// a criacao de um timer foi um arremedo que fiz para que o municipio seja excluido da grade
/// tentei excluir diretamente ou dar um rebuild, mas este componente dá um erro de recursividade.
///
timerRefresh = new Timer();
timerRefresh.Tick += delegate
{
timerRefresh.Stop();
timerRefresh.Dispose();
this.grid2.RefreshMunicipiosDefinidos();
};
timerRefresh.Start();
}
示例15: BrowseSamplesForm
public BrowseSamplesForm()
{
this.InitializeComponent();
this.webBrowser.DocumentStream = new MemoryStream(Encoding.UTF8.GetBytes("Connecting..."));
this.webBrowser.Navigating += new WebBrowserNavigatingEventHandler(this.webBrowser_Navigating);
this.EnableControls();
base.Icon = Resources.LINQPad;
Timer tmr = new Timer();
tmr.Tick += delegate (object sender, EventArgs e) {
if (!this.IsDisposed)
{
this.webBrowser.Navigate("http://www.linqpad.net/RichClient/SampleLibraries.aspx");
}
tmr.Dispose();
};
tmr.Start();
}