titanium-as / TitaniumAS.Opc.Client

Open source .NET client library for OPC DA
MIT License
193 stars 94 forks source link

ReadAsync Does Not Seem to Work Properly #48

Open gitrkenn opened 3 years ago

gitrkenn commented 3 years ago

First, this is a great package and I have been using it for a while with very good success. However, recently started implementing async/await TAP pattern to main program and ran into some issues with ReadAsync. It does not appear to work with implementation as shown below:

Attempt 1: The below runs inside another async method.

var cts = new CancellationTokenSource(TimeSpan.FromMilliseconds(2500));
OpcDaItemValue[] readValues = await group.ReadAsync(group.Items, cts.Token);

-- seems like the cancellation token does not have any effect

Attempt 2:: The below runs inside another async method.

var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromMilliseconds(2500));
OpcDaItemValue[] readValues = await group.ReadAsync(group.Items, cts.Token);

-- seems like the cancellation token does not have any effect

Also, if group.Items count happens to be 0, the ReadAsync fails somewhere and hangs and never returns to the caller.