mirror of
https://github.com/OpenLogics/MewtocolNet.git
synced 2025-12-06 11:11:23 +00:00
Made poller delay thread safe
- added property for currentlly queued messages - added (optional) progress to ReadByteRange
This commit is contained in:
@@ -168,7 +168,7 @@ namespace MewtocolNet {
|
||||
|
||||
iteration++;
|
||||
|
||||
await Task.Delay(PollerDelayMs);
|
||||
await Task.Delay(pollerDelayMs);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -52,13 +52,24 @@ namespace MewtocolNet {
|
||||
set { connectTimeout = value; }
|
||||
}
|
||||
|
||||
private int pollerDelayMs = 0;
|
||||
private volatile int pollerDelayMs = 0;
|
||||
/// <summary>
|
||||
/// Delay for each poller cycle in milliseconds, default = 0
|
||||
/// </summary>
|
||||
public int PollerDelayMs {
|
||||
get { return pollerDelayMs; }
|
||||
set { pollerDelayMs = value; }
|
||||
get => pollerDelayMs;
|
||||
set {
|
||||
pollerDelayMs = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PollerDelayMs)));
|
||||
}
|
||||
}
|
||||
|
||||
private volatile int queuedMessages;
|
||||
/// <summary>
|
||||
/// Currently queued Messages
|
||||
/// </summary>
|
||||
public int QueuedMessages {
|
||||
get => queuedMessages;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -721,7 +732,9 @@ namespace MewtocolNet {
|
||||
//send request
|
||||
try {
|
||||
|
||||
queuedMessages++;
|
||||
var response = await queue.Enqueue(() => SendSingleBlock(_msg));
|
||||
queuedMessages--;
|
||||
|
||||
if (response == null) {
|
||||
return new CommandResult {
|
||||
|
||||
@@ -112,8 +112,9 @@ namespace MewtocolNet {
|
||||
/// </summary>
|
||||
/// <param name="start">Start adress</param>
|
||||
/// <param name="count">Number of bytes to get</param>
|
||||
/// <param name="onProgress">Gets invoked when the progress changes, contains the progress as a double</param>
|
||||
/// <returns>A byte array or null of there was an error</returns>
|
||||
public async Task<byte[]> ReadByteRange (int start, int count) {
|
||||
public async Task<byte[]> ReadByteRange (int start, int count, Action<double> onProgress = null) {
|
||||
|
||||
var byteList = new List<byte>();
|
||||
|
||||
@@ -146,6 +147,9 @@ namespace MewtocolNet {
|
||||
|
||||
}
|
||||
|
||||
if(onProgress != null)
|
||||
onProgress((double)i / wordLength);
|
||||
|
||||
}
|
||||
|
||||
return byteList.ToArray();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<PackageId>MewtocolNet</PackageId>
|
||||
<Version>0.5.6</Version>
|
||||
<Version>0.5.7</Version>
|
||||
<Authors>Felix Weiss</Authors>
|
||||
<Company>Womed</Company>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
|
||||
Reference in New Issue
Block a user