Issue #296: MtApi5 - Added property CommandTimeout to define time for waiting result of response from MetaTrader. Default value 30 sec

This commit is contained in:
Viacheslav Demydiuk
2026-04-06 20:22:10 +03:00
parent 249b0f9fbb
commit fa1e6b6c62
4 changed files with 44 additions and 3 deletions
+14 -1
View File
@@ -32,11 +32,24 @@ namespace MtApi5
private HashSet<int> _experts = [];
private Dictionary<int, Mt5Quote> _quotes = [];
private volatile int _command_timeout = 30000; // 30 seconds
#endregion
#region Public Methods
private IMtLogger Log { get; }
// Time in milliseconds to wait for a response from MetaTrader for a command. Default is 30 seconds.
public int CommandTimeout
{
get => _command_timeout;
set
{
if (value <= 0)
throw new ArgumentException("Command timeout must be greater than zero.");
_command_timeout = value;
}
}
public MtApi5Client(IMtLogger? log = null)
{
_mtEventHandlers[Mt5EventTypes.OnBookEvent] = ReceivedOnBookEvent;
@@ -3588,7 +3601,7 @@ namespace MtApi5
var payloadJson = payload == null ? string.Empty : JsonConvert.SerializeObject(payload);
Log.Debug($"SendCommand: sending '{payloadJson}' ...");
var responseJson = client.SendCommand(expertHandle, (int)commandType, payloadJson);
var responseJson = client.SendCommand(expertHandle, (int)commandType, payloadJson, CommandTimeout);
Log.Debug($"SendCommand: received response JSON [{responseJson}]");