Add start() method to Periodic (and construct stopped)
This commit is contained in:
parent
487427cf0a
commit
e275fa01ed
@ -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() {
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user