本文整理汇总了C#中System.Timers.Timer类的典型用法代码示例。如果您正苦于以下问题:C# Timer类的具体用法?C# Timer怎么用?C# Timer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Timer类属于System.Timers命名空间,在下文中一共展示了Timer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateHeartbeat
public void UpdateHeartbeat()
{
// Create or Update External XML For Last Update Check DateTime
if (!File.Exists(CheckUpdateFile))
{
DateTime DateTimeNow = DateTime.Now;
XmlWriterSettings wSettings = new XmlWriterSettings();
wSettings.Indent = true;
XmlWriter writer = XmlWriter.Create(CheckUpdateFile, wSettings);
writer.WriteStartDocument();
writer.WriteComment("This file is generated by WWIV5TelnetServer - DO NOT MODIFY.");
writer.WriteStartElement("WWIV5UpdateStamp");
writer.WriteStartElement("LastChecked");
writer.WriteElementString("DateTime", DateTimeNow.ToString());
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
}
// Do Update Check
updateTimer = new System.Timers.Timer(1000 * 60 * 60); // Hourly - Release Code
//updateTimer = new System.Timers.Timer(1000 * 10); // 10 Seconds for Testing Only
updateTimer.Elapsed += new ElapsedEventHandler(DoUpdateCheck);
updateTimer.AutoReset = true;
updateTimer.Enabled = true;
if (Properties.Settings.Default.checkUpdates == "On Startup")
{
DoUpdateCheck(null, null);
}
}
示例2: StartTimer
/// <summary>
/// Start timer function
/// </summary>
private void StartTimer()
{
timer = new Timer(TimerInterval);
timer.Elapsed += new ElapsedEventHandler(TimerEvent);
timer.AutoReset = true;
timer.Enabled = true;
}
示例3: InitializeImpl
protected override void InitializeImpl()
{
this._timers = this.TimerJobs
.Where(j => j.Item1 > 0.0)
.OrderBy(j => j.Item1)
.Select(j =>
{
Timer timer = new Timer(j.Item1);
timer.Elapsed += (sender, e) =>
{
timer.Stop();
try
{
this.Host.RequestManager.Execute<Object>(Request.Parse(j.Item2));
}
finally
{
timer.Start();
}
};
return timer;
}).ToList();
this.RunInitializingJobs();
base.InitializeImpl();
}
示例4: HomeViewModel
public HomeViewModel()
{
timer = new Timer(1000);
timer.Elapsed += TimerElapsed;
timer.AutoReset = true;
timer.Start();
}
示例5: SamplingTargetPointGenerator
public SamplingTargetPointGenerator(int samplesPerSecond)
{
workerTimer = new Timer(1000 / samplesPerSecond);
workerTimer.Elapsed += this.WorkerTimerElapsed;
workerTimer.AutoReset = false;
workerTimer.Start();
}
示例6: Server
public Server()
{
config = new INIReader(System.IO.File.ReadAllLines("config.ini"));
chat = new ServerChat();
instance = this;
vehicleController = new ServerVehicleController();
api = new ServerApi(this);
gamemodeManager = new GamemodeManager(api);
gamemodeManager.loadFromFile("gamemodes/" + config.getString("gamemode"));
server = new TcpListener(IPAddress.Any, config.getInt("game_port"));
server.Start();
server.BeginAcceptTcpClient(onIncomingConnection, null);
playerpool = new List<ServerPlayer>();
Timer timer = new Timer();
timer.Elapsed += onBroadcastTimer;
timer.Interval = config.getInt("broadcast_interval");
timer.Enabled = true;
timer.Start();
UDPStartPort = config.getInt("udp_start_port");
Timer timer_slow = new Timer();
timer_slow.Elapsed += timer_slow_Elapsed;
timer_slow.Interval = config.getInt("slow_interval");
timer_slow.Enabled = true;
timer_slow.Start();
http_server = new HTTPServer();
Console.WriteLine("Started game server on port " + config.getInt("game_port").ToString());
Console.WriteLine("Started http server on port " + config.getInt("http_port").ToString());
}
示例7: Run
protected override void Run ()
{
if (!Taskbar.TaskbarManager.IsPlatformSupported) {
return;
}
bool areFileExtensionsRegistered = this.Initialize ();
if (!areFileExtensionsRegistered) {
return;
}
this.updateTimer = new Timer (1000);
this.updateTimer.Elapsed += this.OnUpdateTimerEllapsed;
this.updateTimer.AutoReset = false;
this.recentFiles = DesktopService.RecentFiles;
this.recentFiles.Changed += this.OnRecentFilesChanged;
try {
UpdateJumpList();
} catch (Exception ex) {
MonoDevelop.Core.LoggingService.LogError ("Could not update jumplists", ex);
}
}
示例8: ExchangesWindow
public ExchangesWindow()
{
InitializeComponent();
DataContext = this;
Exchanges = new ObservableCollection<Exchange>();
List<Exchange> tmpExchanges;
using (var entityContext = new MyDBContext())
{
tmpExchanges = entityContext.Exchanges.Include("Sessions").OrderBy(x => x.Name).ToList();
}
foreach (Exchange e in tmpExchanges)
{
Exchanges.Add(e);
}
ExchangesGrid.ItemsSource = Exchanges;
_filterTimer = new Timer();
_filterTimer.Enabled = false;
_filterTimer.AutoReset = false;
_filterTimer.Interval = 100; //milliseconds
_filterTimer.Elapsed += _filterTimer_Elapsed;
}
示例9: ServerLog
/// <summary>
/// Creates a new Instance of the ServerLog
/// </summary>
public ServerLog()
{
_buffer = new StringBuilder(4096);
_writetimer = new Timer();
_writetimer.Interval = 5000;
_writetimer.Elapsed += _writetimer_Elapsed;
}
示例10: MainWindow
public MainWindow()
{
InitializeComponent();
_timer = new Timer(30000);
_timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
_timer.Enabled = true;
}
示例11: Ux2CampaignService
public Ux2CampaignService()
{
InitializeComponent();
//this.cExcHandler = new GanoExceptionHandling(EXC_URL, cErrorFile);
LoadSettings();
if (!EventLog.SourceExists(EVENT_LOG_SOURCE))
EventLog.CreateEventSource(EVENT_LOG_SOURCE, EVENT_LOG);
try
{
this.cScheduleTimer = new System.Timers.Timer(this.cInterval);
this.cScheduleTimer.Elapsed += new ElapsedEventHandler(cScheduleTimer_Elapsed);
this.cScheduleTimer.Enabled = true;
EventLog.WriteEntry(EVENT_LOG_SOURCE, "Ux2 Campaign Service Started on " + DateTime.Now.ToString() + "\n" +
"Settings loaded from " + Path.GetDirectoryName(Application.ExecutablePath) + "\\" + SETTINGS_FILE + "\n" +
"Processing Interval: " + this.cInterval + "ms\n" +
"Max Campaign Age: " + this.cMaxAge + "hours");
this.cProcessor = new ScheduleProcessor(this.cConnectionString, cMaxAge);
this.cProcessorCaller = new CallScheduleProcessor(this.cProcessor.ProcessSchedules);
}
catch (Exception exc)
{
//this.cExcHandler.LogExceptionQuiet(null, exc);
EventLog.WriteEntry(EVENT_LOG_SOURCE, exc.Message);
}
}
示例12: CreateMainLoopTimer
public Object CreateMainLoopTimer(MainServerLoop mainLoop, uint period)
{
myTimer = new Timer(period);
myTimer.Elapsed += (sender, e) => {mainLoop();};
myTimer.Enabled = true;
return myTimer;
}
示例13: btnStart_Click
private void btnStart_Click(object sender, RoutedEventArgs e)
{
this.txtID.Text = string.Empty;
this.txtName.Text = string.Empty;
this.LblResult.Text = string.Empty;
try
{
Init();
int interval = 20;
timer = new Timer();
timer.Interval = interval;
timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
timer.AutoReset = true;
timer.Enabled = true;
timer.Start();
this.btnStart.IsEnabled = false;
this.btnStop.IsEnabled = true;
this.btnStop.Focus();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
示例14: RxTimerStage
/// <summary>Constructs a Rx timer stage</summary>
/// <param name="observer">the observer</param>
/// <param name="initialDelay">the initial delay in milli-seconds</param>
/// <param name="period">the period in milli-seconds</param>
public RxTimerStage(IObserver<PeriodicEvent> observer, long initialDelay, long period)
{
_observer = observer;
_timer = new Timer(period);
_timer.Elapsed += (sender, e) => OnTimedEvent(sender, e, _observer, _value);
_timer.Enabled = true;
}
示例15: Server
/// <summary>
/// Create an new Instance of the TCP-Listener on Port 5000
/// </summary>
internal Server()
{
try
{
AnrlDB.AnrlDataContext db = new AnrlDB.AnrlDataContext();
if (!db.DatabaseExists())
{
db.CreateDatabase();
}
CalculateTabels = new System.Timers.Timer(20000);
CalculateTabels.Elapsed += new ElapsedEventHandler(CalculateTabels_Elapsed);
CalculateTabels.Start();
running = true;
this.tcpListener = new TcpListener(IPAddress.Any, 5000);
this.listenThread = new Thread(new ThreadStart(ListenForClients));
this.listenThread.Start();
db.Dispose();
}
catch (Exception ex)
{
Logger.Log("Exception in Server.Server" + ex.ToString(), 11);
}
}