Skip to content

Monitoring

Monitor transfer progress in real-time using observables or the managed monitor for UI binding.

IHttpTransferManager manager; // injected
manager
.WhenUpdateReceived()
.Subscribe(result =>
{
Console.WriteLine($"Transfer: {result.Request.Identifier}");
Console.WriteLine($"Status: {result.Status}");
Console.WriteLine($"Progress: {result.Progress.PercentComplete:P0}");
Console.WriteLine($"Speed: {result.Progress.BytesPerSecond} B/s");
Console.WriteLine($"ETA: {result.Progress.EstimatedTimeRemaining}");
});
manager
.WatchTransfer("upload-1")
.Subscribe(
result =>
{
Console.WriteLine($"Progress: {result.Progress.PercentComplete:P0}");
},
error =>
{
Console.WriteLine($"Failed: {error.Message}");
},
() =>
{
Console.WriteLine("Transfer completed!");
}
);
manager
.WatchCount()
.Subscribe(count =>
{
Console.WriteLine($"Active transfers: {count}");
});
PropertyTypeDescription
RequestHttpTransferRequestThe original request
StatusHttpTransferStateCurrent transfer state
ProgressTransferProgressProgress details
ExceptionException?Error details if failed
PropertyTypeDescription
BytesPerSecondlongCurrent transfer speed
BytesToTransferlong?Total bytes (null if indeterminate)
BytesTransferredlongBytes transferred so far
PercentCompletedouble0-1 range, or -1 if indeterminate
EstimatedTimeRemainingTimeSpanEstimated completion time
ValueDescription
PendingQueued, waiting to start
InProgressCurrently transferring
PausedPaused by user/system
PausedByNoNetworkPaused due to no network
PausedByCostedNetworkPaused due to metered network
CompletedSuccessfully completed
ErrorFailed with error
CanceledCancelled by user

HttpTransferMonitor provides an observable collection ideal for binding to UI.

HttpTransferMonitor monitor; // injected (registered by AddHttpTransfers)
// Start monitoring
await monitor.Start(
removeFinished: true,
removeErrors: true,
removeCancelled: true
);
// Bind to the collection
var transfers = monitor.Transfers; // INotifyReadOnlyCollection<HttpTransferObject>
// Each HttpTransferObject has:
// - Identifier, Uri, Type
// - Status, PercentComplete, BytesPerSecond
// - BytesToTransfer, BytesTransferred
// - EstimatedTimeRemaining, IsDeterministic
// Stop monitoring
monitor.Stop();
// Clear completed/errored transfers from the list
monitor.Clear(removeFinished: true, removeCancelled: true, removeErrors: true);