-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathREPLWorker.cs
More file actions
50 lines (43 loc) · 1.16 KB
/
REPLWorker.cs
File metadata and controls
50 lines (43 loc) · 1.16 KB
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
46
47
48
49
50
using ScriptCs;
using ScriptCs.Contracts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FluentAutomation.REPL
{
public class ReplWorker
{
private Repl repl = null;
private int workerCount = 0;
public bool InProgress
{
get { return workerCount == 0; }
}
public ReplWorker(Repl repl)
{
this.repl = repl;
}
public void DoWork(Func<Repl, ScriptResult> scriptFunc)
{
this.DoWork(scriptFunc, (a) => { });
}
public void DoWork(Func<Repl, ScriptResult> scriptFunc, Action<ScriptResult> completeFunc)
{
var worker = new BackgroundWorker();
worker.DoWork += (s, e) =>
{
this.workerCount++;
e.Result = scriptFunc(this.repl);
};
worker.RunWorkerCompleted += (s, e) =>
{
this.workerCount--;
completeFunc(e.Result as ScriptResult);
};
worker.RunWorkerAsync();
}
}
}