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


C# Timer.Dispose方法代码示例

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


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

示例1: CallLater

 public static void CallLater(TimeSpan delay, Action method)
 {
     var delayMilliseconds = (int) delay.TotalMilliseconds;
     if (delayMilliseconds < 0)
     {
         throw new ArgumentOutOfRangeException("delay", delay, Properties.Resources.ValueMustBePositive);
     }
     if (method == null)
     {
         throw new ArgumentNullException("method");
     }
     SafeThreadAsyncCall(delegate
     {
         var t = new Timer
         {
             Interval = Math.Max(1, delayMilliseconds)
         };
         t.Tick += delegate
         {
             t.Stop();
             t.Dispose();
             method();
         };
         t.Start();
     });
 }
开发者ID:mookiejones,项目名称:miEditor,代码行数:26,代码来源:MainWindow.xaml.cs

示例2: Run

 internal bool Run()
 {
     bool flag;
     if (this._insideModalLoop)
     {
         throw new InvalidOperationException(Microsoft.ManagementConsole.Internal.Utility.LoadResourceString(Microsoft.ManagementConsole.Internal.Strings.ExceptionInternalConsoleDialogHostAlreadyInsideModalLoop));
     }
     Timer timer = new Timer();
     try
     {
         Application.UseWaitCursor = true;
         this._insideModalLoop = true;
         timer.Tick += new EventHandler(this.OnTimer);
         timer.Interval = (int) this.Timeout.TotalMilliseconds;
         timer.Start();
         this.InnerStart();
         ModalLoop.Run();
         flag = !this._timedOut;
     }
     finally
     {
         timer.Dispose();
         this._timedOut = false;
         this._quitMessagePosted = false;
         this._insideModalLoop = false;
         Application.UseWaitCursor = false;
     }
     return flag;
 }
开发者ID:SiteView,项目名称:ECC8.13,代码行数:29,代码来源:WaitCursor.cs

示例3: LoadShader

 private void LoadShader(string fileName)
 {
     try
     {
         var log = visualContext.AddUpdateFragmentShader(fileName);
         var correctedLineEndings = log.Replace("\n", Environment.NewLine).Trim();
         CallOnChange("Loading '+" + fileName + "' with success!" + Environment.NewLine + correctedLineEndings);
     }
     catch (ShaderLoadException e)
     {
         var correctedLineEndings = e.Message.Replace("\n", Environment.NewLine);
         CallOnChange("Error while compiling shader '" + fileName + "'" + Environment.NewLine + correctedLineEndings);
     }
     catch (FileNotFoundException e)
     {
         CallOnChange(e.Message);
     }
     catch (Exception e)
     {
         //try reload in 2 seconds, because sometimes file system is still busy
         Timer timer = new Timer(); //todo: is this executed on main thread?
         timer.Interval = 2000;
         timer.Tick += (a, b) =>
         {
             timer.Stop();
             timer.Dispose();
             LoadShader(shaderFileName); //if fileName is used here timer will always access fileName of first call and not a potential new one
         };
         timer.Start();
         CallOnChange("Error while accessing shaderfile '" + fileName + "'! Will retry shortly..." + Environment.NewLine + e.Message);
     }
 }
开发者ID:danielscherzer,项目名称:Framework,代码行数:32,代码来源:ShaderFile.cs

示例4: AddToUI

        private Control[] AddToUI(Host host)
        {
            var siteLabel = new Label() {
                AutoSize = true,
                Dock = DockStyle.Fill,
                TabIndex = 1,
                Text = host.HOST,
                TextAlign = System.Drawing.ContentAlignment.MiddleCenter
            };
            var timeLabel = new Label() {
                AutoSize = true,
                Dock = DockStyle.Fill,
                TabIndex = 2,
                TextAlign = System.Drawing.ContentAlignment.MiddleCenter
            };
            var removeButton = new Button() {
                Dock = DockStyle.Fill,
                TabIndex = 3,
                Text = "remove",
                UseVisualStyleBackColor = true
            };

            if (host.END_TIME.HasValue) {
                timeLabel.Text = host.END_TIME.ToString();

                var t = new Timer() {
                    Enabled = true,
                    Interval = 1000
                };

                t.Tick += (sender, e) => {
                    if ((host.END_TIME.Value - DateTime.Now).TotalSeconds > 0) {
                        timeLabel.Text = TimeSpan.Parse(timeLabel.Text).Subtract(new TimeSpan(0, 0, 1)).ToString();
                        t.Dispose();
                    }
                    else {
                        host.Unblock();
                    }
                };

                removeButton.Click += (sender, e) => {
                    host.Unblock();
                };
            } else {
                timeLabel.Text = "routed to " + host.REDIRECT;

                removeButton.Click += (sender, e) => {
                    host.Unblock();
                };
            }

            MainTablePanel.RowCount++;
            MainTablePanel.RowStyles.Add(new RowStyle());
            MainTablePanel.Controls.Add(siteLabel, 0, -1);
            MainTablePanel.Controls.Add(timeLabel, 1, -1);
            MainTablePanel.Controls.Add(removeButton, 2, -1);

            return new Control[] { siteLabel, timeLabel, removeButton };
        }
开发者ID:allonhadaya,项目名称:site-blocker,代码行数:59,代码来源:SiteBlockerForm.cs

示例5: Bomb

 public Bomb(int x, int y)
 {
     base.X = x;
     base.Y = y;
     t = new Timer();
     t.Interval = Settings.BOMB_DURATION;
     t.Tick += (o, e) => { t.Stop(); t.Dispose(); Alive = false; };
     t.Start();
 }
开发者ID:jakkes,项目名称:SnakeGame,代码行数:9,代码来源:Bomb.cs

示例6: Main

        public static void Main()
        {
            try
            {
                Settings.Configurate();

                //database = new Database();
                felhasználó = null;
                database = new Database();

                LoginForm loginform = new LoginForm();
                Application.Run(loginform);
                database = new Database();
                if (loginform.felhasználó != null)
                {
                    felhasználó = loginform.felhasználó;
                    loginform.Dispose();

                    refresher = new Timer();
                    refresher.Interval = Settings.ui_refresh * 1000;
                    refresher.Tick += Refresher_Elapsed;
                    refresher.Start();

                    MainForm mainform = new MainForm();
                    Application.Run(mainform);

                    refresher.Dispose();
                    mainform.Dispose();
                }
            }
            catch (Exception _e)
            {
                MessageBox.Show("Kezeletlen globális hiba a program futása során!\nKérem jelezze a hibát a rendszergazdának!\nHiba adatai:\n" + _e.Message, "Hiba", MessageBoxButtons.OK, MessageBoxIcon.Error);

                string file_name = string.Format("crash-{0:yyyy-MM-dd_hh-mm-ss}.data", DateTime.Now);

                try
                {
                    StreamWriter file = new StreamWriter(file_name);
                    file.WriteLine("Message:\t" + _e.Message);
                    file.WriteLine("Source:\t" + _e.Source);
                    file.WriteLine("Data:\t" + _e.Data);
                    file.WriteLine("Stack:\t" + _e.StackTrace);
                    file.Close();
                }
                catch (Exception _ex)
                {
                    MessageBox.Show("További hiba a kivétel mentésekor!\n" + _ex.Message, "Hiba", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Environment.Exit(1);
                }

                MessageBox.Show("A hiba adatait a " + file_name + " nevű file tartalmazza!", "Hiba adatainak elérése", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Environment.Exit(0);
            }
        }
开发者ID:laszlo-dobcsanyi,项目名称:Labor,代码行数:55,代码来源:Program.cs

示例7: Delay

		/// <summary>
		/// 
		/// </summary>
		/// <param name="milliseconds"></param>
		/// <param name="action"></param>
		public static void Delay(int milliseconds, Action action)
		{
			Timer timer = new Timer();
			timer.Interval = milliseconds;
			timer.Tick += (object sender, EventArgs e) =>
			{
				action.Invoke();
				timer.Stop();
				timer.Dispose();
			};
			timer.Start();
		}
开发者ID:oisy,项目名称:scada,代码行数:17,代码来源:Actions.cs

示例8: btnAddCurrentProcess_Click

 private void btnAddCurrentProcess_Click(object sender, System.EventArgs e)
 {
     MessageBox.Show("After you click OK, you have 3 seconds to select the process", "Select process",
         MessageBoxButtons.OK, MessageBoxIcon.Information);
     Timer lvSelectProcessTimer = new Timer();
     lvSelectProcessTimer.Tick += delegate
     {
         tbxTitle.Text = NativeWin32.GetActiveProcessWindow().Title;
         lvSelectProcessTimer.Stop();
         lvSelectProcessTimer.Dispose();
     };
     lvSelectProcessTimer.Interval = 3000;
     lvSelectProcessTimer.Start();
 }
开发者ID:SHEePYTaGGeRNeP,项目名称:PLSNOPOSTERINO,代码行数:14,代码来源:MainWindowForm.cs

示例9: Dispose

 public void Dispose()
 {
     if (this._top != 0)
     {
         int retries = 0;
         Timer tmr = new Timer {
             Interval = 1,
             Enabled = true
         };
         tmr.Tick += delegate (object sender, EventArgs e) {
             if (++retries > 2)
             {
                 tmr.Dispose();
             }
             try
             {
                 object domDocument = this._browser.Document.DomDocument;
                 object target = domDocument.GetType().InvokeMember("documentElement", BindingFlags.GetProperty, null, domDocument, null);
                 int height = this._top;
                 if (height == -1)
                 {
                     HtmlElement body = this._browser.Document.Body;
                     if (body == null)
                     {
                         return;
                     }
                     height = body.ScrollRectangle.Height;
                 }
                 target.GetType().InvokeMember("scrollTop", BindingFlags.SetProperty, null, target, new object[] { height });
                 tmr.Dispose();
             }
             catch
             {
             }
         };
     }
 }
开发者ID:CuneytKukrer,项目名称:TestProject,代码行数:37,代码来源:SaveBrowserScrollPos.cs

示例10: ShowWithTimeout

 public static DialogResult ShowWithTimeout(this Form form, TimeSpan timeout)
 {
     form.TopMost = true;
     form.AutoSize = true;
     var timoutTimer = new Timer
     {
         Interval = (int)timeout.TotalMilliseconds,
         Enabled = true
     };
     form.Disposed += delegate { timoutTimer.Dispose(); };
     timoutTimer.Tick += delegate
     {
         form.DialogResult = DialogResult.Abort;
         form.Close();
         Console.WriteLine("timed out");
     };
     return form.ShowDialog();
 }
开发者ID:daxfohl,项目名称:FormTimeoutExtension,代码行数:18,代码来源:MyExtensions.cs

示例11: SpringScanner_RetryGetResourceInfo

        public static void SpringScanner_RetryGetResourceInfo(object sender, ZkData.CancelEventArgs<ZkData.SpringScanner.CacheItem> e)
        {
            if (thisInstance != null)
                thisInstance.Dispose();

            if (rememberedResult != null)
            {
                e.Cancel = rememberedResult=="cancel";
                return;
            }

            thisInstance = new PromptForm();
            countDown = new Timer();
            countDown.Tick += (s, e1) => { 
                counter++;
                thisInstance.noButton.Text = "No (" + (30 - counter).ToString() + ")";
                if (counter==31)
                    thisInstance.DialogResult = DialogResult.Cancel;
            };
            countDown.Interval = 1000;
            countDown.Enabled = true;
            counter = 0;
            thisInstance.FormClosed += (s, e1) => { countDown.Dispose(); };
            thisInstance.detailBox.Visible = true;
            thisInstance.Text = "New resource found!";
            thisInstance.questionText.Text = Environment.NewLine + "Server connection failed. Extract \"" + e.Data.FileName + "\" information manually?";
            thisInstance.noButton.Text = "No,Wait";
            Program.ToolTip.SetText(thisInstance.okButton, "Perform UnitSync on this file immediately if UnitSync is available");
            Program.ToolTip.SetText(thisInstance.noButton, "Reask server for map/mod information after 2 minute");
            Program.ToolTip.SetText(thisInstance.rememberChoiceCheckbox, "Remember choice for this session only");
            thisInstance.detailText.WordWrap = false;
            var detailText = "File name: " + e.Data.FileName + Environment.NewLine;
            detailText = detailText + "MD5: " + e.Data.Md5.ToString() + Environment.NewLine;
            detailText = detailText + "Internal name: " + e.Data.InternalName + Environment.NewLine;
            detailText = detailText + "Recommended action: Restore Connection & Wait";
            thisInstance.detailText.Text = detailText;
            thisInstance.ShowDialog();

            e.Cancel = (thisInstance.DialogResult == DialogResult.OK);

            if (thisInstance.rememberChoiceCheckbox.Checked)
                rememberedResult = e.Cancel ? "cancel" : "ok";
        }
开发者ID:Jamanno,项目名称:Zero-K-Infrastructure,代码行数:43,代码来源:UnitSyncRetryPrompt.cs

示例12: SpringScanner_UploadUnitsyncData

        public static void SpringScanner_UploadUnitsyncData(object sender, ZkData.CancelEventArgs<ZkData.IResourceInfo> e)
        {
            if (thisInstance != null)
                thisInstance.Dispose();

            if (rememberedResult != null)
            {
                e.Cancel = rememberedResult == "cancel";
                return;
            }

            thisInstance = new PromptForm();
            countDown = new Timer();
            countDown.Tick += (s, e1) => { 
                counter++;
                thisInstance.okButton.Text = "Ok (" + (30 - counter).ToString() + ")";
                if (counter == 31)
                    thisInstance.DialogResult = DialogResult.OK;
            };
            countDown.Interval = 1000;
            countDown.Enabled = true;
            counter = 0;
            thisInstance.FormClosed += (s, e1) => { countDown.Dispose(); };
            thisInstance.detailBox.Visible = true;
            thisInstance.Text = "New information extracted!";
            thisInstance.questionText.Text = Environment.NewLine + "No server data regarding this file hash. Upload \"" + e.Data.Name + "\" information to server?";
            thisInstance.okButton.Text = "Ok,Share";
            Program.ToolTip.SetText(thisInstance.okButton, "This map/mod will be listed on both ZKL and Springie");
            Program.ToolTip.SetText(thisInstance.noButton, "This map/mod will be listed only on this ZKL");
            Program.ToolTip.SetText(thisInstance.rememberChoiceCheckbox, "Remember choice for this session only");
            thisInstance.detailText.WordWrap = false;
            var detailText = "Resource name: " + e.Data.Name + Environment.NewLine;
            detailText = detailText + "Archive name: " + e.Data.ArchiveName + Environment.NewLine;
            detailText = detailText + "Recommended action: Share multiplayer resource";
            thisInstance.detailText.Text = detailText;
            thisInstance.ShowDialog();

            e.Cancel = (thisInstance.DialogResult == DialogResult.Cancel);

            if (thisInstance.rememberChoiceCheckbox.Checked)
                rememberedResult = e.Cancel ? "cancel" : "ok";
        }
开发者ID:ParzivalX,项目名称:Zero-K-Infrastructure,代码行数:42,代码来源:UnitSyncUploadPrompt.cs

示例13: SafeSetClipboard

		static void SafeSetClipboard(object dataObject)
		{
			// Work around ExternalException bug. (SD2-426)
			// Best reproducable inside Virtual PC.
			int version = unchecked(++SafeSetClipboardDataVersion);
			try {
				Clipboard.SetDataObject(dataObject, true);
			} catch (ExternalException) {
				Timer timer = new Timer();
				timer.Interval = 100;
				timer.Tick += delegate {
					timer.Stop();
					timer.Dispose();
					if (SafeSetClipboardDataVersion == version) {
						try {
							Clipboard.SetDataObject(dataObject, true, 10, 50);
						} catch (ExternalException) { }
					}
				};
				timer.Start();
			}
		}
开发者ID:lisiynos,项目名称:pascalabcnet,代码行数:22,代码来源:ClipboardWrapper.cs

示例14: Test

        public void Test()
        {
            var close = false;
            var form = new Form();
            form.Closing += (s, e) => close = true;
            var xLabel = new Label { Parent = form };
            var yLabel = new Label { Parent = form, Top = 40 };
            var zLabel = new Label { Parent = form, Top = 80 };

            var inputDevices = new XnaInputDevices();
            var keyboard = inputDevices.Keyboard;
            keyboard.On(Button.X).IsDown().Do(() => close = true);
            keyboard.On(Button.Escape).WasReleased().Do(() => close = true);
            keyboard.On(Button.W).WasReleased().Do(() => form.Text = "Pressed");
            keyboard.On(Button.S).IsDown().Do(() => form.Text = "Down");

            var mouse = inputDevices.Mouse;
            mouse.On(Button.LeftMouse).IsDown().Do(() => form.Text = "Left Mouse down");
            mouse.On(Button.RightMouse).WasReleased().Do(() => form.Text = "Right Mouse was pressed");

            mouse.On(Axis.X).Do(delta => xLabel.Text = "X: " + delta);
            mouse.On(Axis.Y).Do(delta => yLabel.Text = "Y: " + delta);
            mouse.On(Axis.Z).Do(delta => zLabel.Text = "Z: " + delta);

            form.Show();

            var timer = new Timer { Interval = 10 };
            timer.Tick += (s, e) => inputDevices.Update();

            timer.Start();

            while (!close)
            {
                Application.DoEvents();
            }
            timer.Stop();
            timer.Dispose();
        }
开发者ID:Christof,项目名称:afterglow,代码行数:38,代码来源:FunctionalTest.cs

示例15: SessionThreadStart

        void SessionThreadStart()
        {
            Monitor.Enter(sessionThread);
            {
                try
                {
                    sessionThreadControl = new Control();
                    sessionThreadControl.CreateControl();

                    session = TtlLiveSingleton.Get();

                    dataTimer = new Timer();
                    dataTimer.Interval = 100;
                    dataTimer.Tick += new EventHandler(dataTimer_Tick);

                    notificationTimer = new Timer();
                    notificationTimer.Interval = 100;
                    notificationTimer.Tick += new EventHandler(notificationTimer_Tick);
                    notificationTimer.Start();
                }
                catch (Exception ex)
                {
                    sessionThreadInitException = ex;
                    TtlLiveSingleton.Dispose();
                }
                Monitor.Pulse(sessionThread);
            }
            Monitor.Exit(sessionThread);

            //Create a message pump for this thread
            Application.Run(applicationContext);

            //Dispose of all stuff on this thread
            dataTimer.Stop();
            dataTimer.Dispose();

            notificationTimer.Stop();
            notificationTimer.Dispose();

            TtlLiveSingleton.Dispose();
            sessionThreadControl.Dispose();

            return;
        }
开发者ID:Faham,项目名称:emophiz,代码行数:44,代码来源:LiveSessionTtl.cs


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