For convenience we have created two classes to enable pool based connections to the MT4 server: ManagerPool and ManagerPoolEx.
For example, you need to manipulate data at MT4 from multiple threads. ManagerAPI is single threaded. ManagerPool makes multiple connections to the MT4 server. And you can get available connecting from pool. It increases total performance at the expense of load to MT4 server.
Example below shows a pool with 8 elements. And 100 threads simultaneously tries to get data from MT4.
public static class ManagerPollExamples
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
public static void GetUsers()
{
var pool = new ManagerPool(Constants.Server, Constants.Login, Constants.Password, maxPollSize: 8)
{
Logger = (ctx, type, message, exception) =>
{
if (exception != null)
Log.Error(exception);
else
Log.Info($"[{type}] {message}");
}
};
pool.Run();
Parallel.For(0, 100, (l, state) =>
{
using (var poolElement = pool.Get(TimeSpan.FromSeconds(3)))
{
var sw = new Stopwatch();
sw.Start();
Log.Debug($"[{l}] requesting users...");
var allUsers = poolElement.Data.Value.UsersRequest();
sw.Stop();
Log.Debug($"[{l}] {allUsers.Count} users requested within {sw.Elapsed}");
}
});
}
}