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) {
|
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() {
|
||||||
|
@ -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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user