C# 修改进度<;T>;回调动作
假设我有以下结构:C# 修改进度<;T>;回调动作,c#,task-parallel-library,C#,Task Parallel Library,假设我有以下结构: public struct TaskWithProgress<TResult> { public Task<TResult> Task { get; set; } public IProgress<double> Progress { get; set; } public string Description { get; set; } public CancellationTokenSource Cance
public struct TaskWithProgress<TResult>
{
public Task<TResult> Task { get; set; }
public IProgress<double> Progress { get; set; }
public string Description { get; set; }
public CancellationTokenSource CancelTokenSource { get; set; }
}
是否有一种方法可以从客户端代码创建此I进程
,然后稍后订阅Report()回调
编辑
我可以使用具体的实现和ProgressChanged事件。。。但是我不能调用IProgress的Report()方法。这里的前进方向是什么?只需使用一个新类的子类
Progress
,该类公开了报告(T值)
方法,并使用该具体类
public class ReportingProgress<T> : Progress<T>, IProgress<T>
{
public ReportingProgress()
{
}
public ReportingProgress(Action<T> handler)
: base(handler)
{
}
public void Report(T value)
{
this.OnReport(value);
}
}
public class ReportingProgress<T> : Progress<T>, IProgress<T>
{
public ReportingProgress()
{
}
public ReportingProgress(Action<T> handler)
: base(handler)
{
}
public void Report(T value)
{
this.OnReport(value);
}
}
[__DynamicallyInvokable]
[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
void IProgress<T>.Report(T value)
{
this.OnReport(value);
}