本文整理汇总了C#中System.Timers.Timer.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Timer.Dispose方法的具体用法?C# Timer.Dispose怎么用?C# Timer.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Timers.Timer
的用法示例。
在下文中一共展示了Timer.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ScriptAssemblyCache
/// <summary>
/// Initializes a new instance of the <see cref="ScriptAssemblyCache"/> class.
/// </summary>
ScriptAssemblyCache()
{
// Get the cache directory
_cacheDir = ContentPaths.Build.Data.Join("ScriptCache");
if (!_cacheDir.EndsWith(Path.DirectorySeparatorChar.ToString()) &&
!_cacheDir.EndsWith(Path.AltDirectorySeparatorChar.ToString()))
_cacheDir += Path.DirectorySeparatorChar;
// Ensure the directory exists
if (!Directory.Exists(_cacheDir))
Directory.CreateDirectory(_cacheDir);
// Load the cache
Load();
// Create the saving timer
_saveAndCleanTimer = new Timer { Interval = _autoSaveRate, AutoReset = true };
_saveAndCleanTimer.Elapsed += _saveTimer_Elapsed;
_saveAndCleanTimer.Start();
// Spawn a new background timer to clean up the junk files a few seconds from now
var cleanTimer = new Timer { Interval = 5 * 1000, AutoReset = false };
cleanTimer.Elapsed += delegate
{
cleanTimer.Dispose();
RemoveUnusedCacheFiles();
};
cleanTimer.Start();
}
示例2: TimersTimer
static void TimersTimer()
{
System.Timers.Timer t1 = new System.Timers.Timer(1000);
t1.AutoReset = true;
t1.Elapsed += TimeAction;
t1.Start();
Thread.Sleep(10000);
t1.Stop();
t1.Dispose();
}
示例3: ProcessRequest
public async void ProcessRequest(HttpContext context)
{
//validate query parameters
QueryParams queryParams;
try
{
queryParams = new QueryParams(context.Request);
}
catch
{
context.Response.StatusCode = 400; //bad request
return;
}
//convert query parameters to entities
var ctx = new DiscCtx(ConfigManager.ConnStr);
var reportParams = queryParams.Materialize(ctx);
if (reportParams == null)
{
context.Response.StatusCode = 400;
return;
}
var screenshotClient = new ReportingPhotonClient();
var reportingTasks = screenshotClient.StartReportingActivities(reportParams.Topic,
reportParams.Discussion,
reportParams.Session);
var complexReportTask = reportingTasks.Item2;
//compute and set report parameters
var report = new Report
{
QueryParams = queryParams,
ReportParams = reportParams,
Participants = Helpers.ParticipantsTuples(reportParams.Topic, reportParams.Session),
ComplexReport = await complexReportTask,
ReportUrl = context.Request.Url.ToString(),
BaseUrl = Helpers.BaseUrl(context.Request)
};
var screenshotTask = reportingTasks.Item1;
report.ReceiveScreenshots(await screenshotTask, context);
var cleanupTimer = new Timer(10*60*1000); //10 minutes
cleanupTimer.Elapsed += (sender, args) =>
{
cleanupTimer.Dispose();
report.Dispose();
screenshotClient.Dispose();
};
cleanupTimer.Start();
context.Response.Write(report.TransformText());
}
示例4: OnCreated
public void OnCreated(ILoading loading)
{
DestroyOld ("DistrictRCIDemand");
var timer = new Timer (10000); //delays GUI hook so other mods such as Building Themes can do its thing
timer.Elapsed += (object sender, ElapsedEventArgs e) => {
HookGUI();
timer.Enabled = false;
timer.Dispose();
};
timer.Enabled = true;
}
示例5: Timer_Dispose_noTicksAnymore
public void Timer_Dispose_noTicksAnymore()
{
global::System.Timers.Timer t = new Timer(100);
var tc = 0;
t.Elapsed += (s, e) => tc++;
t.Start();
Thread.Sleep(200);
t.Dispose();
Thread.Sleep(500);
Assert.Less(tc,3);
Assert.GreaterOrEqual(tc, 1);
}
示例6: WindowsService
public WindowsService()
{
smsTimer = new Timer();
diffTimer = new Timer();
fullTimer = new Timer();
registery = new RegistrySettingManager();
sqlserverManagment = new SqlServerManagement(registery.SqlServer, registery.SqlServerInstance);
file.AutoFlush = true;
file.WriteLine("service newed");
// timer for sms
smsTimer.Interval = 12 * 60 * 60 * 1000;//har 12 saat
smsTimer.AutoReset = true;
smsTimer.Enabled = true;
smsTimer.Elapsed += (x, y) => onSmsTimerElapsed();
// timer for diff backup
diffTimer.Interval = 60 * 1000;//har 1 daghighe
diffTimer.AutoReset = true;
diffTimer.Enabled = true;
diffTimer.Elapsed += (x, y) => {
if (registery.AutomaticBackup
&& registery.LastDiffBackUpTime.HasValue
&& (DateTime.Now - registery.LastDiffBackUpTime.Value).TotalHours >= registery.DiffBackUpPeriod
)
onDiffTimerElapsed();
};
// timer for full backup
fullTimer.Interval = 60*60*1000;//har 1 saat
fullTimer.AutoReset = true;
fullTimer.Enabled = true;
fullTimer.Elapsed += (x, y) =>
{
if (registery.AutomaticBackup
&& registery.LastFullBackUpTime.HasValue
&& (DateTime.Now - registery.LastFullBackUpTime.Value).TotalDays == registery.FullBackUpPeriod
&& DateTime.Parse(registery.FullBackUpTime).TimeOfDay >= DateTime.Now.TimeOfDay)
onFullTimerElapsed();
};
this.Disposed += (x, y) => { smsTimer.Dispose(); fullTimer.Dispose(); diffTimer.Dispose(); file.Close(); };
//service setting
this.ServiceName = "ShayanDentalBackUp";
this.EventLog.Log = "Application";
this.CanHandlePowerEvent = true;
this.CanHandleSessionChangeEvent = true;
this.CanPauseAndContinue = true;
this.CanShutdown = true;
this.CanStop = true;
file.WriteLine("service new" + DateTime.Now);
}
示例7: PortSelector
public PortSelector(bool isNetworkAvailable) {
InitializeComponent();
DeviceRadioButton.Checked += (s, e) => ConnectCommand.RaiseCanExecuteChanged();
NetworkRadioButton.Checked += (s, e) => ConnectCommand.RaiseCanExecuteChanged();
if (!isNetworkAvailable) NetworkRadioButton.Visibility = NetworkControl.Visibility = Visibility.Collapsed;
timer = new Timer {AutoReset = true, Interval = 1000};
timer.Elapsed += timer_Elapsed;
timer.Start();
Closed += (s, e) => timer.Dispose();
}
示例8: Delay
public static void Delay(this Action action, int delayInMilliseconds)
{
var timer = new Timer
{
Interval = delayInMilliseconds,
AutoReset = false
};
timer.Elapsed += delegate
{
timer.Dispose();
action();
};
timer.Start();
}
示例9: CreatePlayerAndGetId
public int CreatePlayerAndGetId(string fileName, uint options)
{
if (options == 1)
{
var timer = new Timer(10);
timer.Elapsed += (sender, args) =>
{
_eventsProvider.Publish(new PlayerCompleted() {Id = 0});
timer.Dispose();
};
timer.Enabled = true;
}
return 0;
}
示例10: ChannelListUpdaterService
public ChannelListUpdaterService(IChatState chatState)
{
connection = chatState.Connection;
cm = chatState.ChatModel;
chatState.EventAggregator.GetEvent<ConnectionClosedEvent>().Subscribe(OnWipeState);
var timer = new Timer(60*1000*1);
timer.Elapsed += (s, e) =>
{
UpdateChannels();
timer.Dispose();
};
timer.Start();
}
示例11: FinishTask
private void FinishTask(ITask task)
{
var TaskType = task.GetType();
var NextTime = task.NextExecutionTime();
_TaskFactory.DestroyTask(task);
var Timer = new Timer();
Timer.Elapsed += (o, e) =>
{
Timer.Dispose();
CreateTask(TaskType);
};
Timer.Interval = NextTime.TotalMilliseconds;
Timer.Start();
}
示例12: Main
static void Main(string[] args)
{
RenderToLedSign(DateTime.Now.ToString("HH:mm"));
m_clockTimer = new Timer();
m_clockTimer.Interval = TimeSpan.FromSeconds(30).TotalMilliseconds;
m_clockTimer.Elapsed += (s,e) => RenderToLedSign(DateTime.Now.ToString("HH:mm"));
m_clockTimer.Start();
Console.WriteLine("Press <Enter> to exit.");
Console.ReadLine();
m_clockTimer.Stop();
m_clockTimer.Dispose();
}
示例13: OnLevelLoaded
public void OnLevelLoaded(LoadMode mode)
{
if (!(mode == LoadMode.LoadGame || mode == LoadMode.NewGame)) {
return;
}
Debug.Print ("OnLevelLoaded()");
DestroyOld ("DistrictRCIDemand");
var timer = new Timer (10000); //delays GUI hook so other mods such as Building Themes can do its thing
timer.Elapsed += (object sender, ElapsedEventArgs e) => {
HookGUI();
timer.Enabled = false;
timer.Dispose();
};
timer.Enabled = true;
}
示例14: TimedUnlock
public static void TimedUnlock()
{
if(Unlock)
{
// Hook up the Elapsed event for the timer.
var timer = new Timer(300);
timer.Elapsed += delegate(System.Object source, ElapsedEventArgs e)
{
timer.Enabled = false;
timer.Dispose();
UnlockPolicyToolbarButton();
};
timer.Enabled = true;
}
}
示例15: NotificationEventArgs
public NotificationEventArgs(string tag, string eventName, string timestamp = "000000000000000", int delayTime = 10000)
{
Tag = tag;
EventName = eventName;
Timestamp = timestamp;
// our timer
var timer = new Timer {Interval = delayTime};
// function that cálled after time elapsed
timer.Elapsed += (sender, args) =>
{
StopMeEvent?.Invoke(this, Empty);
timer.Stop();
timer.Dispose();
};
timer.Start();
}