Click here to Skip to main content
15,902,198 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
[no name] 4-Sep-12 7:37am    
Sounds like you really want to use a timer. Timers are easy to use, not "very hard".
Joan M 4-Sep-12 7:56am    
Explain us exactly what you are after... then we will help.

You can put a sleep inside a thread.
You can use a timer.
You can ...
robo_3d 4-Sep-12 8:14am    
about explaine...i wanna send mail every some hours and every some days...now important hours...how can i do it???
timer not good for this..have some mistake...like when add 4 of 8 hours confused and ,....

1 solution

See this code which executes a task after 5 seconds:
C#:
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:
C#
tmr.Interval = 8*60*60*1000; //8 hours * 60 minutes * 60 seconds * 1000 milliseconds
 
Share this answer
 
v2
Comments
Espen Harlinn 4-Sep-12 8:29am    
Nice and simple :-D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900