-
Notifications
You must be signed in to change notification settings - Fork 277
/
MtCommandTask.cs
executable file
·45 lines (38 loc) · 1.05 KB
/
MtCommandTask.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 System.Threading;
namespace MTApiService
{
public class MtCommandTask
{
private readonly EventWaitHandle _responseWaiter = new AutoResetEvent(false);
private MtResponse _result;
private readonly object _locker = new object();
public MtCommandTask(MtCommand command)
{
if (command == null)
throw new ArgumentNullException(nameof(command));
Command = command;
}
public MtCommand Command { get; }
public MtResponse WaitResult(int time)
{
_responseWaiter.WaitOne(time);
lock (_locker)
{
return _result;
}
}
public void SetResult(MtResponse result)
{
lock (_locker)
{
_result = result;
}
_responseWaiter.Set();
}
public override string ToString()
{
return $"Command = {Command}";
}
}
}