本文整理汇总了C#中System.Timers.Timer.Close方法的典型用法代码示例。如果您正苦于以下问题:C# System.Timers.Timer.Close方法的具体用法?C# System.Timers.Timer.Close怎么用?C# System.Timers.Timer.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Timers.Timer
的用法示例。
在下文中一共展示了System.Timers.Timer.Close方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SystemTimers
static SystemTimers()
{
if(!GameLoopEntry.Initialized)
{
throw new System.InvalidOperationException("Make sure to initialize the GameLoopEntry on the main thread before accessing SystemTimers.");
}
_hookTimer = new System.Timers.Timer(10); //every 10 milliseconds
_hookTimer.Elapsed += OnUpdate;
_hookTimer.Start();
//GameLoopEntry.EarlyUpdate += OnUpdate;
GameLoopEntry.ApplicatinQuit += (s, e) => { if(_hookTimer != null) _hookTimer.Close(); };
}
示例2: BeginGetCustomerDetails
public IAsyncResult BeginGetCustomerDetails(int customerId, AsyncCallback callback, object state)
{
var asyncResult = new SimpleAsyncResult<Customer>(state);
// mimic a long running operation
var timer = new System.Timers.Timer(DelayMilliseconds);
timer.Elapsed += (_, args) =>
{
asyncResult.Result = GetCustomer(customerId);
asyncResult.IsCompleted = true;
callback(asyncResult);
timer.Enabled = false;
timer.Close();
};
timer.Enabled = true;
return asyncResult;
}
示例3: ScheduledEvent
public ScheduledEvent(Event e, uint intervalMinutes, ushort minimumPlayers, uint[] countDownTimes, uint durationSeconds)
: this(e, intervalMinutes, minimumPlayers, countDownTimes)
{
this.durationSeconds = durationSeconds;
endTimer.Interval = durationSeconds * 1000;
endTimer.AutoReset = false;
endTimer.Elapsed += delegate
{
e.stopEvent();
//clear delay 1 minute after event
Timer saveTimer = new Timer(60000);
saveTimer.AutoReset = false;
saveTimer.Elapsed += delegate
{
DGPlugin.clearSaveDelay();
saveTimer.Close();
};
saveTimer.Start();
};
}
示例4: ScheduleAction
/// <summary>
/// Executes a one-shot action that becomes enabled after the given delay.
/// </summary>
private static bool ScheduleAction(Func<bool> action, long interval, long backOff)
{
// Prevent NPE in case of concurrent disconnect
System.Timers.Timer timer = new System.Timers.Timer();
timer.Interval = Math.Max(interval + backOff, 1);// TODO: MinInterval is 1Ms ?
timer.Elapsed += new System.Timers.ElapsedEventHandler((source, e) =>
{
// Stop the Timer
try
{
timer.Enabled = false;
timer.Close();
// DEBUG
//logger.InfoFormat("The Timer #{0} has been disposed.", timer.GetHashCode());
}
catch (ObjectDisposedException) { }
finally
{
action();
}
});
timer.AutoReset = false;
timer.Enabled = true; // Start the Timer
return true;
}
示例5: ShowProgress
internal void ShowProgress()
{
// show green in taskbar for 10 seconds
System.Timers.Timer timer = new System.Timers.Timer(10000);
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Normal);
TaskbarManager.Instance.SetProgressValue(100, 100);
timer.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e)
{
TaskbarManager.Instance.SetProgressValue(0, 0);
TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.NoProgress);
timer.Stop();
timer.Close();
};
timer.Start();
}
示例6: Main
/// <summary>
/// The main.
/// </summary>
/// <param name="args">
/// The args.
/// </param>
// ReSharper disable once UnusedParameter.Local
private static void Main(string[] args)
{
LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter();
Params = ConsumerParams.ReadFromAppSettings();
Console.WriteLine("Starting consumer [{0}]...", Params.Endpoint);
using (IBus bus = new BusFactory().Create(ConfigureBus, false))
{
bus.Start(false);
var t = new Timer(10000);
// ReSharper disable once AccessToDisposedClosure
t.Elapsed += (sender, eventArgs) => ((IBusAdvanced)bus).Panic();
if (Params.Misbehave)
{
t.Start();
}
Console.ReadKey(true);
t.Close();
Console.WriteLine("Shutting down consumer [{0}]...", Params.Endpoint);
}
}
示例7: ResetProgressBar
private void ResetProgressBar(int miliseconds)
{
progressBarTimer = new System.Timers.Timer();
progressBarTimer.Interval = miliseconds;
progressBarTimer.Elapsed += new System.Timers.ElapsedEventHandler((a, b) =>
{
ResetProgressBar();
progressBarTimer.Close();
});
progressBarTimer.Start();
}
示例8: WatcherRoutine
//.........这里部分代码省略.........
break;
// If it is a diff Frame
case Constants.DIFFFRAME:
{
// Reads frame info and length (in bytes)
Int32 lDifframeStartX = lReader.ReadInt32();
Int32 lDifframeStartY = lReader.ReadInt32();
Int32 lWidth = lReader.ReadInt32();
Int32 lHeight = lReader.ReadInt32();
Int32 lVideoLength = lReader.ReadInt32();
if (lVideoLength > 0)
{
// Reads frame bytes
Byte[] lBytes = lReader.ReadBytes(lVideoLength);
// Stores them in memory stream
lStream.Write(lBytes, 0, lBytes.Length);
if (lGraphics != null)
lGraphics.DrawImage(new Bitmap(Image.FromStream(lStream), lWidth, lHeight), lDifframeStartX, lDifframeStartY, lWidth, lHeight);
// Cleans the memory stream
lStream.SetLength(0);
}
}
break;
// If it is data about cursor position
case Constants.CURSOR:
{
// Reads cursor position
Int32 lMouseNewPositionX = lReader.ReadInt32();
Int32 lMouseNewPositionY = lReader.ReadInt32();
// Updates mouse position
if (lMouseNewPositionX != lMouseOldPositionX || lMouseNewPositionY != lMouseOldPositionY)
{
lMouseOldPositionX = lMouseNewPositionX;
lMouseOldPositionY = lMouseNewPositionY;
lPaintPointer = true;
}
}
break;
// Fatal error: socket data has no meaning
default:
throw new Exception("Fatal error: Unrecognized frame type");
}
if (_canUpdate && lGraphics != null)
{
Bitmap lModified = new Bitmap(lCurrent);
// Creates Graphics from copy of current big frame
Graphics lModifiedGraphics = Graphics.FromImage(lModified);
try
{
// Draws cursor position
if (lPaintPointer)
{
lModifiedGraphics.DrawLine(new Pen(Color.Black, Constants.PEN_WIDTH), lMouseOldPositionX, 0, lMouseOldPositionX, lModified.Height);
lModifiedGraphics.DrawLine(new Pen(Color.Black, Constants.PEN_WIDTH), 0, lMouseOldPositionY, lModified.Width, lMouseOldPositionY);
}
// Saves graphics in the copy of current big frame
this.BeginInvoke(this._state.dUpdateVideo, lModified);
}
catch (Exception ex)
{
SmartDebug.DWL(ex.Message);
}
finally
{
lModifiedGraphics.Dispose();
}
_canUpdate = false;
}
}
catch (Exception e)
{
// If something throws an exception ends work
// TODO : must be tolerant to some exceptions?
if (this._state.WorkEnd == false)
{
this._state.WorkEnd = true;
this.BeginInvoke(this._state.dDisconnect);
}
SmartDebug.DWL(e.Message);
}
}
lVideoUpdateTimer.Stop();
lVideoUpdateTimer.Close();
lVideoUpdateTimer.Dispose();
if (lGraphics != null)
{
lGraphics.Dispose();
lGraphics = null;
}
if (lCurrent != null)
{
lCurrent.Dispose();
lCurrent = null;
}
}
示例9: GetFile
//开始接收
private void GetFile(Object savefile)
{
SaveFile sf = (SaveFile)savefile;
SendIndex = sf.index;
FileStream file = new FileStream(sf.path, FileMode.Create, FileAccess.Write); //写入文件流
SendFileSize = filelist[sf.index].filesize;
SendAmount = 0;
SendSize = 0;
TcpListener listen = new TcpListener(Port); //监听端口
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //定义Socket并初始化
try
{
listen.Start(); //开始监听
s = listen.AcceptSocket(); //获取Socket连接
listen.Stop();
byte[] data = new byte[65000]; //定义缓冲区
int longer = data.Length;
if (s.Connected) //确定连接
{
Is_Sending = true;
System.Timers.Timer timer = new System.Timers.Timer(1000); //实例化Timer类,设置间隔时间为10000毫秒
timer.Elapsed += new System.Timers.ElapsedEventHandler(ShowSpeech); //到达时间的时候执行事件
timer.AutoReset = true; //设置是执行一次(false)还是一直执行(true)
timer.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件
int count = s.Receive(data, 0, longer, SocketFlags.None); //把接收到的byte存入缓冲区
file.Write(data, 0, count);
SendAmount += count;
SendSize += count;
while (count != 0 && Is_Send == true)
{
count = s.Receive(data, 0, longer, SocketFlags.None);
file.Write(data, 0, count);
SendAmount += count;
SendSize += count;
}
if (Is_Send == true)
{
CloseSendFile();
ShowFileMessage("接收文件成功!路径:" + sf.path + " 打开文件");
}
s.Close();
file.Close();
timer.Close();
Is_Sending = false;
//隐藏发送列表
SharedFile_List.Dispatcher.Invoke((Action)(() =>
{
SharedFile_List.Visibility = Visibility.Visible;
}));
File_List.Dispatcher.Invoke((Action)(() =>
{
File_List.Visibility = Visibility.Hidden;
}));
}
}
catch (NullReferenceException e)
{
}
}
示例10: SendFile
//开始发送
private void SendFile(object sendfile) //创建set函数
{
SaveFile sf = (SaveFile)sendfile;
SendIndex = sf.index;
SendAmount = 0;
byte[] data = new byte[65000]; //创建文件缓冲区
FileStream file = File.Open(sf.path, FileMode.Open, FileAccess.Read); //创建文件流
int longer = data.Length;
SendFileSize = file.Length;
SendSize = 0;
int end = (int)file.Length; //获取文件长度 文件传送如果有需要超过int的范围估计就要改写FileStream类了
try
{
System.Timers.Timer timer = new System.Timers.Timer(1000); //实例化Timer类,设置间隔时间为10000毫秒
timer.Elapsed += new System.Timers.ElapsedEventHandler(ShowSpeech); //到达时间的时候执行事件
timer.AutoReset = true; //设置是执行一次(false)还是一直执行(true)
timer.Enabled = true; //是否执行System.Timers.Timer.Elapsed事件
while (end != 0 && Is_Send == true)
{
int count = file.Read(data, 0, longer); //把数据写进流
int n = SendFileSocket.Send(data, 0, count, SocketFlags.None); //用Socket的Send方法发送流
SendAmount += n;
SendSize += n;
end -= count;
}
if (Is_Send == true)
{
CloseSendFile();
ShowFileMessage("发送文件成功!");
}
timer.Close(); //关闭显示
file.Close(); //关闭文件流
SendFileSocket.Close(); //关闭Socket
}
catch (NullReferenceException e)
{
}
}
示例11: Show
public void Show(int delay)
{
System.Timers.Timer t = new System.Timers.Timer(delay);
t.Elapsed += (s, e) =>
{
t.Stop();
this.Dispatcher.Invoke(() =>
{
this.Close();
});
t.Close();
t.Dispose();
};
base.Show();
t.Start();
}
示例12: Command
//.........这里部分代码省略.........
if (args.Length > 0)
{
var program = new Program.AutoPickup(gsApi);
switch (args[0])
{
case "my": program.Start(true); break;
case "all": program.Start(false); break;
}
if (program.Enabled)
Manager.Load(program, typeof(Program.AutoPickup).Name);
}
else
{
var program = Manager.Get(typeof(Program.AutoPickup).Name) as Program.AutoPickup;
if (program != null)
Reply(string.Format("Enabled ({0})", program.OnlyMy ? "My" : "All"), name);
else
Reply("Disabled", name);
}
break;
}
case "route":
{
if (args.Length > 0)
switch(args[0])
{
case "record":
if(args.Length > 1)
switch (args[1])
{
case "add":
if (RouteRecord != null && author != null)
{
RouteRecord.Add(author.Position);
RouteRecord.Save();
}
break;
case "del":
if (RouteRecord != null)
{
RouteRecord.Del();
RouteRecord.Save();
}
break;
case "auto":
int period = 1;
if (args.Length == 3)
int.TryParse(args[2], out period);
if (RecordTimer != null)
RecordTimer.Close();
RecordTimer = new System.Timers.Timer(period * 1000);
RecordTimer.Elapsed += (object timer, System.Timers.ElapsedEventArgs ea) =>
{
if (RecordLastPos != author.Position)
{
RecordLastPos = author.Position;
RouteRecord.Add(author.Position);
RouteRecord.Save();
}
};
RecordTimer.Enabled = true;
break;
case "stop":
if (RecordTimer != null)
RecordTimer.Close();
break;
default: //ToDo ../ fix
RouteRecord = new FileRoute(new System.IO.FileInfo(string.Format("{0}.route", args[1])));
break;
}
break;
default:
if (args.Length == 1 && !string.IsNullOrEmpty(name = args[0])) //ToDo ../ fix
{
bool reverse = name.StartsWith("-");
name = (name[0] == '-' || name[0] == '+' ? name.Substring(1) : name);
var route = new FileRoute(new System.IO.FileInfo(string.Format("{0}.route", name)));
route.Load();
if (route.Count > 0)
{
var points = !reverse ? route.Points : route.Points.Reverse();
var program = new Program.Move.SimpleRoute(gsApi);
program.Load(points);
Manager.Load(program, MOVE_PROGRAM);
}
}
break;
}
else if (RouteRecord != null)
Reply(string.Format("Count: {0}, Length: {1}",
RouteRecord.Count, RouteRecord.Length), name);
break;
}
default:
Reply("Don’t understand", name);
break;
}
}