Skip to content

Commit

Permalink
Flush and Dispose streams
Browse files Browse the repository at this point in the history
  • Loading branch information
ShortDevelopment committed Feb 8, 2024
1 parent 5e8e4c7 commit 82e6dd2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions ShortDev.Microsoft.ConnectedDevices.NearShare/TransferToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,28 @@ public void Cancel()
ulong _transferedBytes = 0;
internal void SendProgressEvent(ulong byteTransferDelta)
{
_transferedBytes += byteTransferDelta;
NearShareProgress progress = new()
{
TransferedBytes = _transferedBytes,
TransferedBytes = Interlocked.Add(ref _transferedBytes, byteTransferDelta),
TotalBytes = TotalBytes,
TotalFiles = TotalFiles,
TotalFiles = TotalFiles
};
IsTransferComplete = progress.TransferedBytes >= progress.TotalBytes;
_ = Task.Run(() => Progress?.Invoke(progress));
}
#endregion

public event Action? Finished;
internal void OnFinish()
internal async void OnFinish()
{
_ = Task.Run(() => Finished?.Invoke());
await Task.WhenAll(_acceptPromise.Task.Result.Select(async stream =>
{
await stream.FlushAsync();

stream.Close();
stream.Dispose();
})).ConfigureAwait(continueOnCapturedContext: false);

Finished?.Invoke();
}
}

0 comments on commit 82e6dd2

Please sign in to comment.