mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-07-27 18:47:55 +00:00
45 lines
1.1 KiB
C#
Executable File
45 lines
1.1 KiB
C#
Executable File
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; 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();
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"Command = {Command}";
|
|
}
|
|
}
|
|
} |