When I try to run the AdsClient Connect method in parallel, the following exception is thrown:
AmsConnect: Cannot register Port '0' (Error: ClientPortNotOpen)"
at TwinCAT.Ads.Server.AdsServer.ConnectServer()
at TwinCAT.Ads.AdsClient.Connect(AmsAddress address)
Test-Code to reproduce:
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using TwinCAT.Ads;
using TwinCAT.Ads.Server;
using Xunit;
namespace Beckhoff.TwinCAT.Ads;
public class AdsTest
{
[Fact]
public void ParallelTest()
{
var addresses = new List<AmsAddress>()
{
new AmsAddress("127.0.0.1.1.1", 851),
new AmsAddress("127.0.0.1.1.1", 851),
};
new AdsClient().Invoking(client =>
{
addresses.AsParallel().Select(address =>
{
client.Connect(address);
return true;
}).Count();
}).Should().NotThrow<AdsServerException>();
}
}
When I try to run the AdsClient Connect method in parallel, the following exception is thrown:
AmsConnect: Cannot register Port '0' (Error: ClientPortNotOpen)" at TwinCAT.Ads.Server.AdsServer.ConnectServer() at TwinCAT.Ads.AdsClient.Connect(AmsAddress address)
Test-Code to reproduce: