- acf-02.zip
- Acf
- docs
- lib
- samples
- Corlib
- Arrays
- Boxing
- Delegate
- Environment
- Event
- FileSystem
- Foreach
- MFCReadWrite
- ReadWrite
- Samples.sln
- Samples.txt
- Strings
- Threads
- Timer
- src
- Corlib
- Pal
- tools
- vcide
- AppWizards
- ConsoleApp
- ConsoleApp.txt
- VCProjects
- ACF
- AcfAppWiz.vsdir
- AcfAppWiz.ico
- AcfAppWiz.vsdir
- AcfAppWiz.vsz
- VCWizards
- AcfAppWiz
- Scripts
- 1033
- Templates
- 1033
- readme.txt
- usertype.dat
- acf-01.zip
|
// This is the main project file for VC++ application project
// generated using an Application Wizard.
#include "stdafx.h"
using namespace Acf;
using namespace Acf::Threading;
class StatusChecker : public Object
{
int _invokeCount, _maxCount;
public:
StatusChecker(int count)
{
this->_invokeCount = 0;
this->_maxCount = count;
}
// This method is called by the timer delegate.
void CheckStatus(Object* stateInfo)
{
AutoResetEvent* autoEvent = (AutoResetEvent*)stateInfo;
Console::WriteLine(L"{0} Checking status {1, 2}.",
DateTime::get_Now().ToString(L"h:mm:ss.fff"),
str(++this->_invokeCount));
if (this->_invokeCount == this->_maxCount)
{
// Reset the counter and signal Main.
this->_invokeCount = 0;
autoEvent->Set();
}
}
};
typedef RefPtr<StatusChecker> StatusCheckerPtr;
int _tmain()
{
AutoResetEventPtr autoEvent = new AutoResetEvent(false);
StatusCheckerPtr statusChecker = new StatusChecker(10);
// Create the delegate that invokes methods for the timer.
TimerCallbackPtr timerDelegate =
new TimerCallback(statusChecker, &StatusChecker::CheckStatus);
// Create a timer that signals the delegate to invoke
// CheckStatus after one second, and every 1/4 second
// thereafter.
Console::WriteLine(L"{0} Creating timer.\n",
DateTime::get_Now().ToString(L"h:mm:ss.fff"));
TimerPtr stateTimer =
new Timer(timerDelegate, autoEvent, 1000, 250);
// When autoEvent signals, change the period to every
// 1/2 second.
autoEvent->WaitOne(5000);
stateTimer->Change(0, 500);
Console::WriteLine(L"\nChanging period.\n");
// When autoEvent signals the second time, dispose of
// the timer.
autoEvent->WaitOne(5000);
stateTimer->Dispose();
Console::WriteLine(L"\nDestroying timer.");
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
Yingle Jia is a software engineer located in Beijing, China. He currently works at IBM CSDL (China Software Development Lab). His interests include C++/COM/C#/.NET/XML, etc. He likes coding and writing.
He is the creator of ACF (Another C++ Framework) project. See
http://acfproj.sourceforge.net/.
He also has a blog at
http://blogs.wwwcoder.com/yljia/