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) {
base(TASK_PERIOD_MS);
this.session_manager = session_manager;
start();
}
protected override void task() {

View File

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