Files
mtapi/MTApiService/MtCommandTask.cs
T

37 lines
865 B
C#
Raw Normal View History

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();
}
}
}