睡觉时如何使用我的程序? [英] how can use my program when i used sleep?
本文介绍了睡觉时如何使用我的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
但是当这个睡眠时间达到8个小时或类似的事情时,直到完成睡眠,我才能使用程序的其他部分....
所以现在我该如何使用它呢?
多线程可以实现吗?如果是的话,如何实现?
我知道我为此很难,但是我应该在程序上安排时间表
所以请给我一种带有时间表的方法或源代码
而且...用计时器很难做到
请指导我
解决方案
请参阅此代码,该代码将在5秒钟后执行任务:
C#:
命名空间 WindowsFormsApplication1 { 公共 部分 class Form1:表单 { 公共 Form1() { InitializeComponent(); 计时器tmr = 新 Timer(); tmr.Interval = 5000 ; tmr.Tick + = 新 EventHandler(tmr_Tick); // 做一些工作 tmr.Start(); } 无效 tmr_Tick(对象发送者,EventArgs e) { // 5秒钟后做一些工作 [[Timer)sender).Stop(); } } }
VB.NET:
Namespace WindowsFormsApplication1 Public Partial Class Form1 Inherits Form Public Sub New() InitializeComponent() Dim tmr As New Timer() tmr.Interval = 5000 tmr.Tick += New EventHandler(AddressOf tmr_Tick) ''Do some work tmr.Start() End Sub Private Sub tmr_Tick(sender As Object, e As EventArgs) ''Do some work after 5 seconds DirectCast(sender, Timer).[Stop]() End Sub End Class End Namespace
您觉得这很难吗?只需使用8个小时而不是5秒钟,就可以完成以下操作:
tmr.Interval = 8 * 60 * 60 * 1000; // 8小时* 60分钟* 60秒* 1000毫秒
hi
in my program i use sleep
but when this sleep for 8 hours or some thing like this i can not use of others piece of my program until finished sleeping....
so now how can i use it??
can be possible with multi thread??if yes how??
i know my way is hard for this but i should to have scheduling on my program
so please give me a way or source code with schedule
and...with timer is very hard to do it
please guide me
解决方案
See this code which executes a task after 5 seconds:
C#:
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); Timer tmr = new Timer(); tmr.Interval = 5000; tmr.Tick += new EventHandler(tmr_Tick); //Do some work tmr.Start(); } void tmr_Tick(object sender, EventArgs e) { //Do some work after 5 seconds ((Timer)sender).Stop(); } } }
VB.NET:
Namespace WindowsFormsApplication1 Public Partial Class Form1 Inherits Form Public Sub New() InitializeComponent() Dim tmr As New Timer() tmr.Interval = 5000 tmr.Tick += New EventHandler(AddressOf tmr_Tick) ''Do some work tmr.Start() End Sub Private Sub tmr_Tick(sender As Object, e As EventArgs) ''Do some work after 5 seconds DirectCast(sender, Timer).[Stop]() End Sub End Class End Namespace
Does that look very hard to you? Just use 8 hours instead of 5 seconds and you are done like:
tmr.Interval = 8*60*60*1000; //8 hours * 60 minutes * 60 seconds * 1000 milliseconds
这篇关于睡觉时如何使用我的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文