(原創) 如何使用Timer? (.NET) (C#) (C++/CLI)
C# / SimpleTimer.cs
/*
(C) OOMusou 2007 http://oomusou.cnblogs.com
Filename : SimpleTimer.cs
Compiler : Visual Studio 2005 / C# 2.0
Description : Simple demo for timer
Release : 07/28/2007 1.0
*/
using System;
using System.Threading;
class MyClock {
public static void showTime(Object stateInfo) {
Console.WriteLine("{0}", DateTime.Now.ToString("h:mm:ss:fff"));
}
}
class Client {
static void Main() {
Timer timer = new Timer(new TimerCallback(MyClock.showTime), new AutoResetEvent(false), 0, 250);
while(true);
}
}
(C) OOMusou 2007 http://oomusou.cnblogs.com
Filename : SimpleTimer.cs
Compiler : Visual Studio 2005 / C# 2.0
Description : Simple demo for timer
Release : 07/28/2007 1.0
*/
using System;
using System.Threading;
class MyClock {
public static void showTime(Object stateInfo) {
Console.WriteLine("{0}", DateTime.Now.ToString("h:mm:ss:fff"));
}
}
class Client {
static void Main() {
Timer timer = new Timer(new TimerCallback(MyClock.showTime), new AutoResetEvent(false), 0, 250);
while(true);
}
}
C++/CLI / SimpleTimer.cpp
/*
(C) OOMusou 2006 http://oomusou.cnblogs.com
Filename : SimpleTimer.cpp
Compiler : Visual C++ 8.0 / C++/CLI
Description : Simple demo for timer
Release : 07/28/2007 1.0
*/
#include "stdafx.h"
using namespace System;
using namespace System::Threading;
ref class MyClock {
public:
static void showTime(Object^ stateInfo);
};
void MyClock::showTime(Object^ stateInfo) {
Console::WriteLine("{0}", DateTime::Now.ToString("h:mm:ss:fff"));
}
int main() {
Timer^ timer = gcnew Timer(gcnew TimerCallback(MyClock::showTime), gcnew AutoResetEvent(false), 0, 250);
while(true);
}
(C) OOMusou 2006 http://oomusou.cnblogs.com
Filename : SimpleTimer.cpp
Compiler : Visual C++ 8.0 / C++/CLI
Description : Simple demo for timer
Release : 07/28/2007 1.0
*/
#include "stdafx.h"
using namespace System;
using namespace System::Threading;
ref class MyClock {
public:
static void showTime(Object^ stateInfo);
};
void MyClock::showTime(Object^ stateInfo) {
Console::WriteLine("{0}", DateTime::Now.ToString("h:mm:ss:fff"));
}
int main() {
Timer^ timer = gcnew Timer(gcnew TimerCallback(MyClock::showTime), gcnew AutoResetEvent(false), 0, 250);
while(true);
}