library.network.maui/Network/NetworkTask.cs

47 lines
914 B
C#

namespace Blahblah.Library.Network;
public abstract partial class NetworkTask : IDisposable
{
public string Url { get; }
public CancellationToken Token { get; }
public bool IsCancelled => disposed || Token.IsCancellationRequested == true;
bool disposed;
public void SetCancelled()
{
OnCancelled();
Dispose();
}
public void SetException(Exception ex)
{
OnException(ex);
Dispose();
}
protected abstract void OnCancelled();
protected abstract void OnException(Exception ex);
private partial void DisposingInternal();
public void Dispose()
{
if (!disposed)
{
disposed = true;
DisposingInternal();
}
GC.SuppressFinalize(this);
}
}
public delegate void StepHandler<T>(float progress, T? update);
public delegate string StringHandler(string original);