本文介绍了如何设置线程的时间间隔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过设置时间,线程将在该时间后自动触发.代码为plz是什么. 例如:
By setting the time, Thread will automatically fired after that time.So what is code plz . Ex:
public Form2() { InitializeComponent(); Thread objth = new Thread(ThreadJob); objth.Start(); }推荐答案
System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer.Tick + =新的EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval =新的TimeSpan(0,0,1); dispatcherTimer.Start(); System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(0,0,1); dispatcherTimer.Start();
如果您要在多个时间间隔内启动线程或运行最终exe文件,则最好设置服务器shedular,以便在多个时间间隔后运行exe文件. 希望对您有帮助... If you want to fire your thread or run your final exe in several interval then better to set your server shedular which will run your exe after several interval. Hope it may helps you...
嗨.. 请尝试如下.. Hi.. Please try like below.. static void Main(string[] args) { Console.WriteLine("Main Thread Starting"); Thread.CurrentThread.Name = "Main "; Thread t1 = new Thread(new ThreadStart(run)); t1.Name = "Child"; t1.Start(); for (int i = 0; i < 5; i++) { Console.WriteLine("In thread " + Thread.CurrentThread.Name + i); Thread.Sleep(1000); } Console.WriteLine("Main Thread Terminates"); Console.Read(); } }
更多推荐
如何设置线程的时间间隔?
发布评论