0

I use Clientace of Kepware to communicate with RSLinx OPC Server. But, I can not disconnect RSLinx OPC Server. When I don't use Parallel.Foreach, I can disconnect Server. But, when, I use Parallel.Foreach, I can not disconnect. I have no respose from Clientace of Kepware. How can I disconnect server?

[code]
DaServerMgt daServerMgt = new DaServerMgt();
...
// Disconnect
daServerMgt.Disconnect(); <--- hanging when I use Parallel.Foreach to write value.

// Write
// I use Parallel code for Performance
Parallel.Foreach(tags, (tag) =>
{
    ...
    // itemIdentifiers / itemValues each has only one tag
    daServerMgt.Write(ref itemIdentifiers, itemValues);
    ...
});

/*
// itemIdntifiers / itemValues each has a lot of tags.
daServerMgt.Write(ref itemIdentifiers, itemValues);
*/

1 Answers1

0

(I don't have enough reputation points, so I cannot add a comment)

I have had the experience, that ClientAce behaves unexpectedly when trying to connect from different threads at the same time. You may have the same case. Try to disconnect one after another.

Try either Task.ContinueWith or foreach with await (like in this SO answer)

show
  • 69
  • 1
  • 4
  • Not having rep gives you no permission to put comments here in the Answer section. Please delete this. – Rob Dec 07 '19 at 00:20