-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExecutor.cs
46 lines (37 loc) · 1.13 KB
/
Executor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using bagend_ml.Client;
using bagend_ml.Client.Model;
namespace bagend_ml
{
public class Executor
{
private readonly ILogger<Executor> _logger;
private string _name;
public Executor(ILogger<Executor> logger)
{
_logger = logger;
_name ="executor-" + DateTime.UtcNow.Microsecond;
}
public string GetName()
{
return _name;
}
public void SetName(string name)
{
_logger.LogInformation("executor {} - changing name to {}", _name, name);
_name = name;
}
public void execute(Runnable action)
{
_logger.LogInformation("executor {} - submitting new thread {} to threadpool", _name, action.GetThreadName());
WaitCallback waitCallback = (state) => action.Run();
ThreadPool.QueueUserWorkItem(waitCallback);
}
public void executeImmediately(Runnable action)
{
_logger.LogInformation("executor {} - non-concurrently running new thread {]", _name, action.GetThreadName());
WaitCallback waitCallback = (state) => action.Run();
ThreadPool.QueueUserWorkItem(waitCallback);
}
}
}