Asynchronous is the method of asynchronous execution, this is a good understanding.
What's the use of asynchrony?
I've only heard it before, and I don't want to dispute it. But it was time to meet the need for this.
Like what:
Regular execution, if not asynchronous method, also do not use timer, only with Thread.Sleep to interval.
The execution method itself takes time, and the meaning of timing changes--two times of execution must be more than 1 minutes apart.
Here is the simplest implementation of an asynchronous demo:
using System using System.Collections.Generic; using System.Linq; using
System.Threading;
Using System.Diagnostics;
Namespace ConsoleApplication20 {Class Program {public delegate void Testdelegate (string name);
static void Main (string[] args) {testdelegate d = Test;
Console.WriteLine ("Beginning: {0:yyyy-mm-dd HH:mm:ss.fff}", DateTime.Now);
D.begininvoke ("Xiaoming 1", NULL, NULL);
D.begininvoke ("Xiaoming 2", NULL, NULL);
D.begininvoke ("Xiaoming 3", NULL, NULL);
D.begininvoke ("Xiao Ming 4", NULL, NULL);
D.begininvoke ("Xiaoming 5", NULL, NULL);
Console.WriteLine ("End: {0:yyyy-mm-dd HH:mm:ss.fff}", DateTime.Now);
Console.read (); static void Test (string name) {Console.WriteLine ("TestMethod: {0:yyyy-mm-dd HH:mm:ss.fff}")
{1} ", DateTime.Now, name); }
}
}
Visible by Result: BeginInvoke is indeed asynchronous when invoked.
Attached: Timer code
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Timers;
Using System.Threading;
Namespace ConsoleApplication21
{
class program
{
static void Main (string[] args)
{
System.Timers.Timer Timer = new System.Timers.Timer ();
Timer. Enabled = true;
Timer. Interval = 1000;
Timer. Start ();
Timer. Elapsed + = new Elapsedeventhandler (printpoint);
Console.WriteLine ("End");
Console.read ();
}
static void Printpoint (object sender, Elapsedeventargs e)
{
DateTime dtcurr = DateTime.Now;
Console.WriteLine ("{0:yyyy-mm-dd HH:mm:ss.fff}", Dtcurr);
Thread.Sleep ();
Console.WriteLine ("{0:yyyy-mm-dd hh:mm:ss.fff}_{1:yyyy-mm-dd HH:mm:ss.fff}", Dtcurr, DateTime.Now);}}
The result is visible: The Timer event is also asynchronous, each event even if the execution time is longer, does not cause the next timed event delay execution.