如何设置线程的时间间隔?

编程入门 行业动态 更新时间:2024-10-28 13:22:29
本文介绍了如何设置线程的时间间隔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

通过设置时间,线程将在该时间后自动触发.代码为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(); } }

更多推荐

如何设置线程的时间间隔?

本文发布于:2023-05-27 19:06:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/299904.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:线程   间隔   如何设置   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!