public void Test_ParallelRoboDKConnections() { var stopAsyncTask = false; var rdk = new RoboDK { RoboDKServerStartPort = 10000, Logfile = Path.Combine(Directory.GetCurrentDirectory(), "RoboDk.log"), DefaultSocketTimeoutMilliseconds = 20 * 1000 }; rdk.Connect(); rdk.Render(false); rdk.Command("AutoRenderDelay", 50); rdk.Command("AutoRenderDelayMax", 300); rdk.DefaultSocketTimeoutMilliseconds = 10 * 1000; List <IItem> AddStaticParts() { var parts = new List <IItem>(); var cwd = Directory.GetCurrentDirectory(); parts.Add(rdk.AddFile(Path.Combine(cwd, "TableOut.sld"))); parts.Add(rdk.AddFile(Path.Combine(cwd, "robot.robot"))); return(parts); } List <IItem> AddDynamicParts() { var parts = new List <IItem>(); var cwd = Directory.GetCurrentDirectory(); for (var n = 0; n < 10; n++) { parts.Add(rdk.AddFile(Path.Combine(cwd, "Phone Case Box.sld"))); parts.Add(rdk.AddFile(Path.Combine(cwd, "Box.sld"))); parts.Add(rdk.AddFile(Path.Combine(cwd, "Phone Case Done.sld"))); } return(parts); } // Task which opens a temporary new connection void DoTemporaryConnectionCalls(IReadOnlyCollection <IItem> staticParts) { // ReSharper disable once AccessToModifiedClosure while (!stopAsyncTask) { foreach (var staticPart in staticParts) { Thread.Sleep(1); using (var roboDkLink = new RoboDK.RoboDKLink(staticPart.RDK())) { var clonedItem = staticPart.Clone(roboDkLink.RoboDK); clonedItem.Pose(); } } } } var p = AddStaticParts(); var task = new Task(() => DoTemporaryConnectionCalls(p)); task.Start(); try { for (var i = 0; i < 20; i++) { var dynamicParts = AddDynamicParts(); rdk.Command("CollisionMap", "Off"); rdk.SetCollisionActive(CollisionCheckOptions.CollisionCheckOff); rdk.Delete(dynamicParts); } } catch (Exception ex) { Assert.Fail(ex.Message); } finally { stopAsyncTask = true; } try { task.Wait(); } catch (Exception ex) { Assert.Fail(ex.Message); } finally { rdk.CloseRoboDK(); } }