public MainWindow()
{
InitializeComponent();
Action action = new Action(
delegate()
{
while (true)
{
Thread.Sleep(2000);
Console.WriteLine("I am here");
}
}
);
action.BeginInvoke(null, null);
}
本文展示了一个使用委托创建无限循环后台任务的例子。该任务每隔两秒输出一条消息,展示了如何利用委托和线程来实现后台的持续运行任务。
public MainWindow()
{
InitializeComponent();
Action action = new Action(
delegate()
{
while (true)
{
Thread.Sleep(2000);
Console.WriteLine("I am here");
}
}
);
action.BeginInvoke(null, null);
}
996
2146
5487

被折叠的 条评论
为什么被折叠?