mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-07-28 11:07:48 +00:00
37 lines
865 B
C#
37 lines
865 B
C#
|
|
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)
|
||
|
|
{
|
||
|
|
Command = command;
|
||
|
|
}
|
||
|
|
|
||
|
|
public MtCommand Command { get; private set; }
|
||
|
|
|
||
|
|
public MtResponse WaitResult(int time)
|
||
|
|
{
|
||
|
|
_responseWaiter.WaitOne(time);
|
||
|
|
lock (_locker)
|
||
|
|
{
|
||
|
|
return _result;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void SetResult(MtResponse result)
|
||
|
|
{
|
||
|
|
lock (_locker)
|
||
|
|
{
|
||
|
|
_result = result;
|
||
|
|
}
|
||
|
|
_responseWaiter.Set();
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|