Skip to content

Commit

Permalink
Make ReadPropertyAsync function use tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
YarekTyshchenko committed Dec 8, 2022
1 parent 27eb233 commit 1706ce6
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions BACnetClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1679,16 +1679,27 @@ public Task<IList<BacnetValue>> ReadPropertyAsync(BacnetAddress address, BacnetO
return ReadPropertyAsync(address, objectId, propertyId, invokeId, arrayIndex);
}

public Task<IList<BacnetValue>> ReadPropertyAsync(BacnetAddress address, BacnetObjectId objectId,
public async Task<IList<BacnetValue>> ReadPropertyAsync(BacnetAddress address, BacnetObjectId objectId,
BacnetPropertyIds propertyId, byte invokeId = 0, uint arrayIndex = ASN1.BACNET_ARRAY_ALL)
{
return Task<IList<BacnetValue>>.Factory.StartNew(() =>
using (var result = BeginReadPropertyRequest(address, objectId, propertyId, true, invokeId, arrayIndex))
{
if (!ReadPropertyRequest(address, objectId, propertyId, out IList<BacnetValue> result, invokeId, arrayIndex))
throw new Exception($"Failed to read property {propertyId} of {objectId} from {address}");
for (var r = 0; r < _retries; r++)
{
var buffer = await result.GetResultOrTimeout(Timeout);
if (buffer != null)
{
EndReadPropertyRequest(result, out var valueList, out var ex);
if (ex != null)
throw ex;

return result;
});
return valueList;
}
if (r < Retries - 1)
result.Resend();
}
}
throw new Exception($"Failed to read property {propertyId} of {objectId} from {address}");
}

public BacnetAsyncResult BeginReadPropertyRequest(BacnetAddress address, BacnetObjectId objectId, BacnetPropertyIds propertyId, bool waitForTransmit, byte invokeId = 0, uint arrayIndex = ASN1.BACNET_ARRAY_ALL)
Expand Down

0 comments on commit 1706ce6

Please sign in to comment.