Add start() method to Periodic (and construct stopped)

This commit is contained in:
Camden Dixie O'Brien 2025-03-02 17:44:44 +00:00
parent 487427cf0a
commit e275fa01ed
2 changed files with 13 additions and 4 deletions

View File

@ -112,6 +112,7 @@ namespace StudySystemClient {
public Worker(SessionManager session_manager) { public Worker(SessionManager session_manager) {
base(TASK_PERIOD_MS); base(TASK_PERIOD_MS);
this.session_manager = session_manager; this.session_manager = session_manager;
start();
} }
protected override void task() { protected override void task() {

View File

@ -6,17 +6,25 @@ namespace StudySystemClient {
protected Periodic(uint period_ms) { protected Periodic(uint period_ms) {
this.period_ms = period_ms; this.period_ms = period_ms;
exit = false; exit = true;
thread = new Thread<void>("Periodic task", body);
} }
~Periodic() { ~Periodic() {
if (!exit) {
exit = true; exit = true;
thread.join(); thread.join();
} }
}
protected abstract void task(); protected abstract void task();
public void start() {
if (exit) {
exit = false;
thread = new Thread<void>("Periodic task", body);
}
}
private void body() { private void body() {
while (!exit) { while (!exit) {
task(); task();