本文整理汇总了C#中System.Timers.Timer.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# System.Timers.Timer.Stop方法的具体用法?C# System.Timers.Timer.Stop怎么用?C# System.Timers.Timer.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Timers.Timer
的用法示例。
在下文中一共展示了System.Timers.Timer.Stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TakePictureInternal
protected override void TakePictureInternal(Action<byte[]> callback)
{
List<byte[]> pictures = new List<byte[]>();
var timer = new System.Timers.Timer(3000);
int count = 0;
timer.Elapsed += (sender, args) =>
{
++count;
if (count > 3)
{
timer.Stop();
byte[] result = ProcessImages(pictures);
callback(result);
return;
}
timer.Stop();
ImageProcessor.DoTakePicture(stream =>
{
pictures.Add(stream);
timer.Start();
});
};
timer.Start();
}
示例2: WaitForRoom
public bool WaitForRoom(Boss boss)
{
Random rand = new Random();
int patience = rand.Next(0, 41);
bool entered = false;
Console.WriteLine(this.name + " Poczekam " + patience / 2 + " minut na wolne miejsce w poczekalni");
System.Timers.Timer timer = new System.Timers.Timer();
timer.Elapsed += (sender, e) =>
{
patience--;
if (patience > 0)
{
entered = HandleRoom(boss);
if (entered == true)
{
Console.WriteLine(this.name + " Zanim wyszedłem pojawiło się miejsce w poczekalni. Wchodzę do poczekalni.");
timer.Stop();
}
}
else
{
Console.WriteLine(this.name + " Skończyła mi się cierpliwość. Wychodzę.");
entered = false;
timer.Stop();
}
};
timer.Interval = 500;
timer.Enabled = true;
return entered;
}
示例3: StartLifetimedThread
/// <summary>
/// Start a Thread that will close after a delay
/// </summary>
/// <param name="threadAction">Action to be performed by the Thread</param>
/// <param name="actionOnElapsed">Action to be performed when the Timer is over</param>
/// <param name="closureDelay">Delay before stopping the thread</param>
/// <param name="initializationDelay">
/// Delay required for the threadAction to be ready to be Tested
/// </param>
/// <param name="initialDelay">Delay before a Thread is started</param>
public static Thread StartLifetimedThread(
Action threadAction,
Action actionOnElapsed,
long closureDelay,
int initializationDelay = 0,
int initialDelay = 0)
{
Thread t = new Thread(() =>
{
if (closureDelay > 0)
{
Timer timer = new Timer(closureDelay);
timer.Elapsed += (sender, args) =>
{
timer.Stop();
if (actionOnElapsed != null)
{
actionOnElapsed();
}
};
timer.Start();
threadAction();
timer.Stop();
}
});
if (initialDelay != 0)
{
Timer initialTimer = new Timer(initialDelay);
initialTimer.Elapsed += (sender, args) =>
{
initialTimer.Stop();
t.Start();
Thread.Sleep(initializationDelay);
};
initialTimer.Start();
}
else
{
t.Start();
Thread.Sleep(initializationDelay);
}
return t;
}
示例4: TestLeapPlayerLoop
public void TestLeapPlayerLoop()
{
for (int i = 0; i < 3; i++)
{
var testOver = new ManualResetEventSlim();
var timeoutTimer = new Timer(10000);
var player = new LeapPlayer(@"frames\rotate_1.frames");
player.LoopOutput = true;
var bytesExpected = player.FileSizeInBytes * 3;
Action<Frame> frameListener = frame =>
{
timeoutTimer.Stop();
timeoutTimer.Start();
if (player.TotalBytesRead >= bytesExpected)
{
testOver.Set();
}
};
player.FrameReady += frameListener;
timeoutTimer.Elapsed += (sender, args) => testOver.Set();
player.StartConnection();
timeoutTimer.Start();
testOver.Wait();
player.StopConnection();
Assert.IsTrue(player.TotalBytesRead >= bytesExpected);
}
}
示例5: 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);
}
}
示例6: Run
public void Run()
{
while (true)
{
var security = new PipeSecurity();
security.SetAccessRule(new PipeAccessRule("Administrators", PipeAccessRights.FullControl, AccessControlType.Allow));
using (pipeServer = new NamedPipeServerStream(
Config.PipeName,
PipeDirection.InOut,
NamedPipeServerStream.MaxAllowedServerInstances,
PipeTransmissionMode.Message,
PipeOptions.None,
Config.BufferSize, Config.BufferSize,
security,
HandleInheritability.None
))
{
try
{
Console.Write("Waiting...");
pipeServer.WaitForConnection();
Console.WriteLine("...Connected!");
if (THROTTLE_TIMER)
{
timer = new Timer
{
Interval = THROTTLE_DELAY,
};
timer.Elapsed += (sender, args) => SendMessage();
timer.Start();
while(pipeServer.IsConnected)Thread.Sleep(1);
timer.Stop();
}
else
{
while (true) SendMessage();
}
}
catch(Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
finally
{
if (pipeServer != null)
{
Console.WriteLine("Cleaning up pipe server...");
pipeServer.Disconnect();
pipeServer.Close();
pipeServer = null;
}
}
}
}
}
示例7: RunAndWaitForProcess
public static int RunAndWaitForProcess(string fileName, string arguments = "" , int timeout = 0)
{
Process proc = new System.Diagnostics.Process ();
if(timeout != 0){
System.Timers.Timer timer = new System.Timers.Timer(timeout);
timer.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e) {
timer.Stop();
proc.Kill();
};
timer.Start();
}
proc.EnableRaisingEvents = false;
if (arguments == "") {
Console.WriteLine ("Starting process: {0}", fileName);
}
else
{
Console.WriteLine ("Starting process: {0} with arguments: {1}", fileName, arguments);
}
proc.StartInfo.FileName = fileName;
proc.StartInfo.Arguments = arguments;
proc.Start ();
proc.WaitForExit ();
return proc.ExitCode;
}
示例8: Main
public static void Main(string[] args) {
/*var test = new Test();
var watch = new Stopwatch();
var measures = new List<double>();
for (int p = 1; p < Environment.ProcessorCount + 1; ++p) {
for (int i = 0; i < 10; i++) {
test.Run(watch, p);
measures.Add(watch.ElapsedMilliseconds);
}
Console.WriteLine("With {0} threads:{1}".Fmt(p, measures.Average()));
}*/
var timer = BucketTimer.Create("tests", new long[] {10, 100, 500});
Thread thread = new Thread(Run);
thread.Start(timer);
var t = new System.Timers.Timer(30000);
t.Elapsed += (sender, event_args) => Poll(timer);
t.Start();
Console.WriteLine("Done");
Console.WriteLine();
Console.ReadLine();
t.Stop();
}
示例9: PrepareDialog
/// <summary>
/// Call this immediately before the line that shows the OpenFile or SaveFile dialog. It is only necessary if you have
/// set the dialog.FileName property. When this is set there is a real possibility that the full file name will be
/// clipped on the left so you only visually see the right-most 10 or 11 characters. (The full name is still in the property though).
/// </summary>
/// <param name="AFilenameWithoutPath">Specify the filename. The method only does anything for names longer than 10 characters</param>
public static void PrepareDialog(String AFilenameWithoutPath)
{
Version ver = Environment.OSVersion.Version;
// Check for a 'long' name in Windows Vista (6.0) and Win7 (6.1). The bug is fixed in Win8 (6.2)
if ((AFilenameWithoutPath.Length > 10)
&& (Environment.OSVersion.Platform == PlatformID.Win32NT)
&& (ver.Major == 6)
&& (ver.Minor < 2))
{
// Set up a timer, interval and event handler
System.Timers.Timer timer = new System.Timers.Timer();
timer.Interval = 500;
timer.Elapsed += delegate
{
timer.Stop();
// SHIFT + (HOME then END) will select the complete name
SendKeys.SendWait("+({HOME}{END})");
};
// Start the timer that will in 500 ms fire off our SendKeys once the dialog is shown
timer.Start();
}
}
示例10: NaviMessengerService
public NaviMessengerService()
{
naviMessenger = new Messenger(new NaviHandler(this));
InitEnvParameters();
ConnectPIC32();
//Create navigation algorithms thread
ThreadAlgorithm = new Thread(new ThreadStart(algorithms));
ThreadAlgorithm.IsBackground = true;
ThreadAlgorithm.Priority = System.Threading.ThreadPriority.AboveNormal;
//Init timer1
timer1 = new System.Timers.Timer();
timer1.Interval = 200;
timer1.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Tick);
timer1.Stop();
//Init manual mode timer
ManModeTimer = new System.Timers.Timer();
ManModeTimer.Interval = 100;
ManModeTimer.Elapsed += new System.Timers.ElapsedEventHandler(ManModeTimerHandler);
ManModeTimer.Stop();
//Read config from default.set and process map
ProcessConfigMap();
//Connect beacon and start sendcoordinatetimer and TagDataRecvTimer
ConnectBeacon();
}
示例11: InitializeClickTimer
void InitializeClickTimer()
{
_clickTimer = new System.Timers.Timer(200);
_clickTimer.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) =>
{
_clickTimer.Stop();
if (_lastMouseUpTicks - _last2MouseDownTicks < TimeSpan.TicksPerMillisecond * 500)
{
System.Diagnostics.Debug.WriteLine("Mouse double click");
if (OnMouseDoubleClicked != null)
{
InvokeOnMainThread(() =>
{
OnMouseDoubleClicked(this, _lastMouseUpEvent);
});
}
}
else
{
System.Diagnostics.Debug.WriteLine("Mouse click");
if (OnMouseClicked != null)
{
InvokeOnMainThread(() =>
{
OnMouseClicked(this, _lastMouseUpEvent);
});
}
}
ResetMouseClick();
};
}
示例12: Main
static void Main(string[] args)
{
ObjectBase.Container = MEFLoader.Init();
System.Console.WriteLine("Starting up services");
System.Console.WriteLine("");
SM.ServiceHost hostStyleManger = new SM.ServiceHost(typeof(StyleManager));
SM.ServiceHost hostProductManger = new SM.ServiceHost(typeof(ProductManager));
/* More services to call */
StartService(hostStyleManger, "StyleManger Host");
StartService(hostProductManger, "ProductManager Host");
System.Timers.Timer timer = new System.Timers.Timer(10000);
timer.Elapsed += OnTimerElapsed;
timer.Start();
System.Console.WriteLine("eCommerce Monitor has started.");
System.Console.WriteLine("");
System.Console.WriteLine("Press [Enter] to exit.");
System.Console.ReadLine();
timer.Stop();
System.Console.WriteLine("eCommerce Monitor stopped.");
StopService(hostStyleManger, "AccountManager Host");
StopService(hostProductManger, "AccountManager Host");
}
示例13: ChangeTracker
public ChangeTracker()
{
_timer = new System.Timers.Timer(400);
_timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_elapsed);
_timer.Enabled = true;
_timer.AutoReset = false;
_timer.Stop();
}
示例14: AutoFolderMonitor
public AutoFolderMonitor(TVDoc Doc,UI ui)
{
mDoc = Doc;
mUI = ui;
mScanDelayTimer = new System.Timers.Timer(1000);
mScanDelayTimer.Elapsed += new System.Timers.ElapsedEventHandler(mScanDelayTimer_Elapsed);
mScanDelayTimer.Stop();
}
示例15: ExportingDialog
public ExportingDialog(iMetaLibrary.Scanners.MovieScanner MovieScanner, iMetaLibrary.Scanners.TvScanner TvScanner)
{
this.Build ();
notebook1.ShowTabs = false;
notebook1.ShowBorder = false;
bkgWorker = new System.ComponentModel.BackgroundWorker();
bkgWorker.WorkerSupportsCancellation = true;
bkgWorker.DoWork += HandleBkgWorkerDoWork;
System.Timers.Timer pulsar = new System.Timers.Timer(50) { AutoReset = true};
pulsar.Elapsed += delegate {
pbarExporting.Pulse();
};
this.buttonCancel.Clicked += delegate(object sender, EventArgs e)
{
bkgWorker.CancelAsync();
this.Destroy();
};
this.buttonOk.Clicked += delegate(object sender, EventArgs e) {
if(notebook1.Page == 0)
{
string folder = filechooserbutton1.Filename;
if(String.IsNullOrEmpty(folder) || !System.IO.Directory.Exists(folder)){
MessageBox.Show("Invalid export location specfied.");
return;
}
this.buttonOk.Visible = false;
bkgWorker.RunWorkerAsync(new object[] { folder, MovieScanner, TvScanner} );
pulsar.Start();
notebook1.Page = 1;
}
else
{
// final page.
this.Destroy();
}
};
bkgWorker.RunWorkerCompleted += delegate(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) {
pulsar.Stop();
if(e.Result as bool? == true)
{
notebook1.Page = 2;
this.buttonOk.Visible = true;
this.buttonCancel.Visible = false;
}
else
{
notebook1.Page = 3;
this.buttonOk.Visible = true;
this.buttonCancel.Visible = false;
}
};
}