Created
September 11, 2012 13:52
-
-
Save runceel/3698649 to your computer and use it in GitHub Desktop.
BackgroundWorker interface sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename TProgress> | |
class BackgroundWorker | |
{ | |
private: | |
TProgress progress_; | |
bool reportChanged_; | |
public: | |
BackgroundWorker(bool reportChanged = false) : | |
progress_(TProgress()), | |
reportChanged_(reportChanged) | |
{ | |
} | |
BackgroundWorker(const TProgress &progress, bool reportChanged = false) : | |
progress_(progress), | |
reportChanged_(reportChanged) | |
{ | |
} | |
void Run() | |
{ | |
for (int i = 0; i < 10; i++) | |
{ | |
int report = progress_.Execute(); | |
if (reportChanged_) | |
{ | |
this->Report(report); | |
} | |
} | |
} | |
private: | |
void Report(int report) | |
{ | |
progress_.Report(report); | |
} | |
}; | |
struct Progress | |
{ | |
int count; | |
int Execute() | |
{ | |
std::cout << "exec!!" << std::endl; | |
return count++; | |
} | |
void Report(int report) | |
{ | |
std::cout << report << std::endl; | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment