当前位置: 首页>>代码示例>>C#>>正文


C# System.Threading.Timer.Dispose方法代码示例

本文整理汇总了C#中System.Threading.Timer.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# System.Threading.Timer.Dispose方法的具体用法?C# System.Threading.Timer.Dispose怎么用?C# System.Threading.Timer.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Threading.Timer的用法示例。


在下文中一共展示了System.Threading.Timer.Dispose方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildSample

        public static void BuildSample(IAppBuilder app)
        {
            // add eventsource middleware
            app.EventSource(envKey);
            app.Run(context => {

                // get the event stream (not captured yet)
                var eventStream = context.Environment[envKey] as IEventStream;

                // create some timers to send mesages
                var timer = new System.Threading.Timer(_ => {
                    var ts = DateTime.UtcNow.ToString("O");
                    eventStream.WriteAsync("Timer1:" + ts + message + "\n");
                }, null, 1,  50);
                var timer2 = new System.Threading.Timer(_ => {
                    var ts = DateTime.UtcNow.ToString("O");
                    eventStream.WriteAsync("Timer 2:" + ts + "\n");
                }, null, 1,  25);

                // Capture the eventstream by calling Open and pass in the 
                // clean-up logic for when this client closes the stream
                var task =  eventStream.Open(() => {
                    Console.WriteLine("Closed");
                    timer.Dispose();
                    timer2.Dispose();
                });

                eventStream.WriteAsync("Started\n");
                return task;
            });
        }
开发者ID:Xamarui,项目名称:OwinUtils,代码行数:31,代码来源:EventSourceSample.cs

示例2: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            this.button1.Text = "A";

            System.Threading.Timer t = new System.Threading.Timer((o) => { }, null, 0, 1000);
            t.Dispose();
            string a = "";
        }
开发者ID:Yuanxiangz,项目名称:WorkSpace,代码行数:8,代码来源:Form1.cs

示例3: Delay

        public static Task Delay(int milliseconds)
        {
#if NET_4_0
            var tcs = new TaskCompletionSource<int>();
            var timer = new System.Threading.Timer(_ => tcs.SetResult(0), null, milliseconds, System.Threading.Timeout.Infinite);
            return tcs.Task.ContinueWith(t => timer.Dispose(), TaskScheduler.Default);
#else
            return Task.Delay(milliseconds);
#endif
        }
开发者ID:nunit,项目名称:nunit,代码行数:10,代码来源:AsyncTestDelegates.cs

示例4: RealMain


//.........这里部分代码省略.........
                catch (ArgumentOutOfRangeException)
                {
                    //Bugfix for older Mono, slightly more resources used to avoid large values in the period field
                    PurgeTempFilesTimer = new System.Threading.Timer(purgeTempFilesCallback, null, TimeSpan.FromHours(1), TimeSpan.FromHours(1));
                }

                LiveControl = new LiveControls(DataConnection.ApplicationSettings);
                LiveControl.StateChanged += new EventHandler(LiveControl_StateChanged);
                LiveControl.ThreadPriorityChanged += new EventHandler(LiveControl_ThreadPriorityChanged);
                LiveControl.ThrottleSpeedChanged += new EventHandler(LiveControl_ThrottleSpeedChanged);

                Program.WorkThread = new Duplicati.Library.Utility.WorkerThread<Runner.IRunnerData>((x) =>
                {
                    Runner.Run(x, true);
                }, LiveControl.State == LiveControls.LiveControlState.Paused);
                Program.Scheduler = new Scheduler(WorkThread);

                Program.WorkThread.StartingWork += (worker, task) => { SignalNewEvent(null, null); };
                Program.WorkThread.CompletedWork += (worker, task) => { SignalNewEvent(null, null); };
                Program.WorkThread.WorkQueueChanged += (worker) => { SignalNewEvent(null, null); };
                Program.Scheduler.NewSchedule += new EventHandler(SignalNewEvent);
                Program.WorkThread.OnError += (worker, task, exception) => { Program.DataConnection.LogError(task == null ? null : task.BackupID, "Error in worker", exception); };

                Action<long, Exception> registerTaskResult = (id, ex) => {
                    lock(Program.MainLock) {

                        // If the new results says it crashed, we store that instead of success
                        if (Program.TaskResultCache.Count > 0 && Program.TaskResultCache.Last().Key == id)
                        {
                            if (ex != null && Program.TaskResultCache.Last().Value == null)
                                Program.TaskResultCache.RemoveAt(Program.TaskResultCache.Count - 1);
                            else
                                return;
                        }

                        Program.TaskResultCache.Add(new KeyValuePair<long, Exception>(id, ex));
                        while(Program.TaskResultCache.Count > MAX_TASK_RESULT_CACHE_SIZE)
                            Program.TaskResultCache.RemoveAt(0);
                    }
                };

                Program.WorkThread.CompletedWork += (worker, task) => { registerTaskResult(task.TaskID, null); };
                Program.WorkThread.OnError += (worker, task, exception) => { registerTaskResult(task.TaskID, exception); };

                Program.WebServer = new WebServer.Server(commandlineOptions);

                if (Program.WebServer.Port != DataConnection.ApplicationSettings.LastWebserverPort)
                    ServerPortChanged = true;
                DataConnection.ApplicationSettings.LastWebserverPort = Program.WebServer.Port;

                if (Library.Utility.Utility.ParseBoolOption(commandlineOptions, "ping-pong-keepalive"))
                {
                    Program.PingPongThread = new System.Threading.Thread(PingPongMethod);
                    Program.PingPongThread.IsBackground = true;
                    Program.PingPongThread.Start();
                }

                ServerStartedEvent.Set();
                ApplicationExitEvent.WaitOne();
            }
            catch (SingleInstance.MultipleInstanceException mex)
            {
                System.Diagnostics.Trace.WriteLine(Strings.Program.SeriousError(mex.ToString()));
                if (writeConsole)
                    Console.WriteLine(Strings.Program.SeriousError(mex.ToString()));
                else
                    throw mex;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(Strings.Program.SeriousError(ex.ToString()));
                if (writeConsole)
                    Console.WriteLine(Strings.Program.SeriousError(ex.ToString()));
                else
                    throw new Exception(Strings.Program.SeriousError(ex.ToString()), ex);
            }
            finally
            {
                StatusEventNotifyer.SignalNewEvent();

                if (UpdatePoller != null)
                    UpdatePoller.Terminate();
                if (Scheduler != null)
                    Scheduler.Terminate(true);
                if (WorkThread != null)
                    WorkThread.Terminate(true);
                if (Instance != null)
                    Instance.Dispose();
                if (PurgeTempFilesTimer != null)
                    PurgeTempFilesTimer.Dispose();

                if (PingPongThread != null)
                    try { PingPongThread.Abort(); }
                    catch { }

                if (LogHandler != null)
                    LogHandler.Dispose();

            }
        }
开发者ID:kztao,项目名称:duplicati,代码行数:101,代码来源:Program.cs

示例5: auxProcess_Exited

 /// <summary>
 /// This event fires when the process we have a refrence to exits
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void auxProcess_Exited(object sender, EventArgs e)
 {
     if (_aux.KeepAlive)
     {
         OnStatusChange(this, new StatusChangeEventArgs(_aux.Name + " has stopped!"));
         //unsubscribe
         _auxProcess.Exited -= auxProcess_Exited;
         end();
         //restart as required
         if (!_stopping)
         {
             OnStatusChange(this, new StatusChangeEventArgs("Re-starting " + _aux.Name));
             //wait some seconds first
             System.Threading.AutoResetEvent autoEvent = new System.Threading.AutoResetEvent(false);
             System.Threading.Timer t = new System.Threading.Timer((x) => { start(); autoEvent.Set(); }, null, 5000, System.Threading.Timeout.Infinite);
             autoEvent.WaitOne();
             t.Dispose();
         }
         else
         {
             OnStatusChange(this, new StatusChangeEventArgs(_aux.Name + " stopped"));
             Running = false;
         }
     }
     else
     {
         OnStatusChange(this, new StatusChangeEventArgs(_aux.Name + " has completed"));
         //unsubscribe
         _auxProcess.Exited -= this.auxProcess_Exited;
         _auxProcess.Dispose();
         Running = false;
     }
 }
开发者ID:cjmurph,项目名称:PmsService,代码行数:38,代码来源:AuxiliaryApplicationMonitor.cs

示例6: plex_Exited

        /// <summary>
        /// This event fires when the plex process we have a reference to exits
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void plex_Exited(object sender, EventArgs e)
        {
            OnPlexStatusChange(this, new StatusChangeEventArgs("Plex Media Server has stopped!"));
            //unsubscribe
            _plex.Exited -= plex_Exited;

            //kill the supporting processes.
            killSupportingProcesses();

            if (_plex != null)
            {
                _plex.Dispose();
                _plex = null;
            }

            //restart as required
            Settings settings = SettingsHandler.Load();
            if (State != PlexState.Stopping && settings.AutoRestart)
            {
                OnPlexStatusChange(this, new StatusChangeEventArgs(string.Format("Waiting {0} seconds before re-starting the Plex process.", settings.RestartDelay)));
                State = PlexState.Pending;
                System.Threading.AutoResetEvent autoEvent = new System.Threading.AutoResetEvent(false);
                System.Threading.Timer t = new System.Threading.Timer((x) => { Start(); autoEvent.Set(); }, null, settings.RestartDelay * 1000, System.Threading.Timeout.Infinite);
                autoEvent.WaitOne();
                t.Dispose();
            }
            else
            {
                //set the status
                State = PlexState.Stopped;
            }
        }
开发者ID:cjmurph,项目名称:PmsService,代码行数:37,代码来源:PmsMonitor.cs

示例7: Restart

 /// <summary>
 /// Restart plex, wait for the specified delay between stop and start
 /// </summary>
 /// <param name="msDelay">The amount of time in ms to wait before starting after stop</param>
 internal void Restart(int delay)
 {
     Stop();
     State = PlexState.Pending;
     System.Threading.AutoResetEvent autoEvent = new System.Threading.AutoResetEvent(false);
     System.Threading.Timer t = new System.Threading.Timer((x) => { Start(); autoEvent.Set(); }, null, delay, System.Threading.Timeout.Infinite);
     autoEvent.WaitOne();
     t.Dispose();
 }
开发者ID:cjmurph,项目名称:PmsService,代码行数:13,代码来源:PmsMonitor.cs

示例8: Wait

        private static void Wait()
        {
            Int32 intProcessWaitInMins = 1;
            if (System.Configuration.ConfigurationManager.AppSettings["ProcessWaitInMins"] != null)
                intProcessWaitInMins = Int32.TryParse(System.Configuration.ConfigurationManager.AppSettings["ProcessWaitInMins"].ToString(), out intProcessWaitInMins) ? intProcessWaitInMins : 1;

            WriteProcessToMonitor("Waiting " + intProcessWaitInMins.ToString("#,##0") + "Mins for next process...");

            // Create a Timer object that knows to call our TimerCallback
            // method once every 2000 milliseconds.
            iTmrCtr = 0;
            System.Threading.Timer t = new System.Threading.Timer(TimerCallback, null, 0, 2000);

            System.Threading.Thread.Sleep(60000 * intProcessWaitInMins);

            t.Dispose(); // Cancel the timer now
            Console.WriteLine();
        }
开发者ID:marioricci,项目名称:erp-luma,代码行数:18,代码来源:Program.cs

示例9: TempFileManager

		private TempFileManager()
		{
			// set up timer to periodically remove expired entries
			_timer = new Timer(TimerCallback, null, SweepInterval, SweepInterval);

			// also remove all entries when the desktop is shutdown
			// (it isn't nice to have this dependency here, but seems to be no other easy way to do this)
			Desktop.Application.Quitting +=
				(sender, args) =>
					{
						_timer.Dispose();
						Clean(obj => true);
					};
		}
开发者ID:UIKit0,项目名称:ClearCanvas,代码行数:14,代码来源:TempFileManager.cs

示例10: RunMinimizeTest

 int RunMinimizeTest()
 {
     stateCount =-1;
     time1 = 0;
     time2 = 0;
     System.Threading.Timer timer = new System.Threading.Timer(KillTest, null, 1000, 1000);
     System.Threading.ThreadStart test = new System.Threading.ThreadStart(RunMinimize);
     currTest = new System.Threading.Thread(test);
     currTest.Start();
     while (stateCount == -1)
     {
         System.Threading.Thread.Sleep(50);
     }
     timer.Dispose();
     return stateCount;
 }
开发者ID:AutomataDotNet,项目名称:Automata,代码行数:16,代码来源:RexTests.cs

示例11: Main

        public static void Main(string[] args)
        {
            EventWithCallback ec = new EventWithCallback();
            for (int i = 0; i < 500; i++)
            {
                System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
                {
                    ec.Wait(String.Format("world. From Thread {0:X}", System.Threading.Thread.CurrentThread.GetHashCode()));

                }));
                t.Start();
            }

            var timer = new System.Threading.Timer(new System.Threading.TimerCallback(timercb), ec, 0, 2000);
            Console.ReadLine();
            timer.Dispose();
        }
开发者ID:debugthings,项目名称:waiterandbtree,代码行数:17,代码来源:Program.cs


注:本文中的System.Threading.Timer.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。