我想让一个Windows Service 在某天的某个时间运行一次(一天运行一次),我加一个timer,然后在timer1_Elapsed方法中我是这样写的: if(DateTime.Now.ToLongTimeString()=="10:49:55")
{
// do something...
}服务也安装成功了,可以就是不运行里面的方法,是怎么回事啊??
=======================================================
我原来是这样写:
if(DateTime.Now.Hour==2) {
// do something...
}
这样就能运行,但是我发现这样不是每天运行一次,是每天运行很多次.
请教!!!
{
// do something...
}服务也安装成功了,可以就是不运行里面的方法,是怎么回事啊??
=======================================================
我原来是这样写:
if(DateTime.Now.Hour==2) {
// do something...
}
这样就能运行,但是我发现这样不是每天运行一次,是每天运行很多次.
请教!!!
if ( now >= 你要执行时间总秒数 )
{
do something...
}
我刚才建了一个Winform.结果在那个时间把运行的窗体跳出来了.有没有运行时没有什么显示的程序类型啊?
谢谢
using System.Threading;// Simple threading scenario: Start a static method running
// on a second thread.
public class ThreadExample {
// The ThreadProc method is called when the thread starts.
// It loops ten times, writing to the console and yielding
// the rest of its time slice each time, and then ends.
public static void ThreadProc() {
for (int i = 0; i < 10; i++) {
Console.WriteLine("ThreadProc: {0}", i);
// Yield the rest of the time slice.
Thread.Sleep(0);
}
} public static void Main() {
Console.WriteLine("Main thread: Start a second thread.");
// The constructor for the Thread class requires a ThreadStart
// delegate that represents the method to be executed on the
// thread. C# simplifies the creation of this delegate.
Thread t = new Thread(new ThreadStart(ThreadProc));
// Start ThreadProc. On a uniprocessor, the thread does not get
// any processor time until the main thread yields. Uncomment
// the Thread.Sleep that follows t.Start() to see the difference.
t.Start();
//Thread.Sleep(0); for (int i = 0; i < 4; i++) {
Console.WriteLine("Main thread: Do some work.");
Thread.Sleep(0);
} Console.WriteLine("Main thread: Call Join(), to wait until ThreadProc ends.");
t.Join();
Console.WriteLine("Main thread: ThreadProc.Join has returned. Press Enter to end program.");
Console.ReadLine();
}
}