Home Web Front-end JS Tutorial Example code sharing of c# timer

Example code sharing of c# timer

Jun 26, 2017 pm 02:49 PM
.net timer

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 计时器
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            label1.Text = DateTime.Now.ToString();
            System.Timers.Timer t = new System.Timers.Timer(1000);//实例化Timer类,设置间隔时间为1000毫秒 就是1秒;
            t.Elapsed += new System.Timers.ElapsedEventHandler(theout);//到达时间的时候执行事件;
            t.AutoReset = true;//设置是执行一次(false)还是一直执行(true);
            t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
           
        }
        public void theout(object source, System.Timers.ElapsedEventArgs e)
        {
            this.Invoke(new TextOption(f));//invok 委托实现跨线程的调用
        }

        delegate void TextOption();//定义一个委托

        void f()
        {
            label1.Text = DateTime.Now.ToString();//调用内容,并用lable1显示出来。。。
        }

       
    }
}
Copy after login

The above is the detailed content of Example code sharing of c# timer. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to set multiple timers on iPhone iOS 17 How to set multiple timers on iPhone iOS 17 Sep 18, 2023 am 09:01 AM

In iOS 17, you can set multiple timers on your iPhone using the Clock app, or use Siri to set it hands-free. We discuss both in this article. Let's take a look at them. Set Multiple Timers on iPhone Using the Clock App Open the Clock app on your iPhone and tap the Timers tab in the lower right corner. Now, set the hours, minutes, and seconds. You can use the "Label" and "When does the timer end" options to set a name for the timer and a preferred tone when the timer completes. This will help you differentiate between timers. Once done, click the "Start" button. Then, click the "+" icon in the upper right corner. Now, repeat the above steps to set multiple timers on iPhone. You can also browse

How to use multiple timers on iPhone with iOS 17 How to use multiple timers on iPhone with iOS 17 Jun 21, 2023 am 08:18 AM

What are multi-timers on iOS17? In iOS17, Apple now offers users the ability to set multiple timers at once on their iPhone. This is a welcome change, one that many have been waiting for for years. The Clock app, which before iOS 16 only allowed users to set one timer at a time, can now be used to activate any number of timers, making it ideal for completing multiple tasks at once. You can set any number of timers in the timer screen. Once the timer is started, all active timers will appear as "Live Activity" notifications on the lock screen and Notification Center. From here, you can view the remaining time until the timer is off, pause, or stop the timer without opening the Clock app. when you are on the clock

Windows 7 timer location introduction Windows 7 timer location introduction Jul 08, 2023 pm 11:53 PM

Where is the timer in windows 7? Some customers want to know where the countdown is in win7 when using win7. In fact, win7 does not have its own timer, but there is a clock that can keep time. So the following is an introduction to the location of the timer in windows 7. First, according to personality Open it, then find the options of the taskbar and menu bar, then customize with Acura, find the clock, and select Open, so that you can proceed to the technology through the clock. Very simple and fast. Where is the timer in Windows 7? When the computer screen is blank, right-click and select "Personalize". Select the "Taskbar and Menu Bar" option. After opening it, in the taskbar tab, there is a status bar area below. Click the custom button and click "Open" below.

What are the employment prospects of C#? What are the employment prospects of C#? Oct 19, 2023 am 11:02 AM

Whether you are a beginner or an experienced professional, mastering C# will pave the way for your career.

How to set a timer on your iPhone camera How to set a timer on your iPhone camera Apr 14, 2023 am 10:43 AM

How long can you set a timer on your iPhone camera? When you access the timer options in the iPhone's camera app, you'll be given the option to choose between two modes: 3 seconds (3s) and 10 seconds (10s). The first option lets you take a quick selfie from the front or rear camera while you're holding your iPhone. The second option is useful in scenes where you can mount your iPhone on a tripod from a distance to click group photos or selfies. How to Set a Timer on an iPhone Camera While setting a timer on an iPhone camera is a fairly simple process, exactly how to do it varies depending on the iPhone model you're using.

Share several .NET open source AI and LLM related project frameworks Share several .NET open source AI and LLM related project frameworks May 06, 2024 pm 04:43 PM

The development of artificial intelligence (AI) technologies is in full swing today, and they have shown great potential and influence in various fields. Today Dayao will share with you 4 .NET open source AI model LLM related project frameworks, hoping to provide you with some reference. https://github.com/YSGStudyHards/DotNetGuide/blob/main/docs/DotNet/DotNetProjectPicks.mdSemanticKernelSemanticKernel is an open source software development kit (SDK) designed to integrate large language models (LLM) such as OpenAI, Azure

Teach you step by step how to use decorators to extend Python timers Teach you step by step how to use decorators to extend Python timers Apr 13, 2023 pm 08:46 PM

This is our third article to teach you step by step how to implement a Python timer. The first two articles: teach you step by step how to implement a Python timer, and use context managers to extend Python timers, making our Timer class convenient to use, beautiful and practical. But we are not satisfied with this, there is still a use case that can simplify it further. Suppose we need to track the time spent in a given function in our code base. With a context manager, you basically have two different options: 1. Use ​Timer every time you call a function: with Timer("some_name"): do_something() When we are in

How to use built-in Pomodoro technology in Windows 11/10 How to use built-in Pomodoro technology in Windows 11/10 Mar 11, 2024 am 09:40 AM

To use built-in Pomodoro technology in Windows 11 or Windows 10, you can set a timer through the built-in Clock app. This can help you use your time more effectively and improve work efficiency. Using Pomodoro technology allows you to focus on completing tasks in a short period of time and avoid distractions and procrastination. The built-in clock app provides convenient timing and reminder functions to help you work according to the Pomodoro technology work cycle. By setting working hours and break times, you can better manage your time and increase work efficiency. Therefore, using the built-in tools provided by the Windows system to practice Pomodoro technology can help you complete your work tasks more efficiently. Po

See all articles