寻找.NET 4.5 Progress T。源代码 [英] Looking for .NET 4.5 Progress<T> source code
本文介绍了寻找.NET 4.5 Progress T。源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我没有安装.NET 4.5(并且无法安装)。
I don't have .NET 4.5 installed (and I can't install it).
在哪里可以找到新的<$ c的源代码$ c> System.Progress< T> 类?
Where can I find the source code of the new System.Progress<T>
class ?
(或者足够友好的人,安装了.NET 4.5 Beta,可以复制/粘贴代码)
(Or someone kind enough, with the .NET 4.5 beta installed, to copy/paste the code)
推荐答案
以下是ILSpy的输出:
Here is the output from ILSpy:
using System;
using System.Runtime;
using System.Threading;
namespace System
{
[__DynamicallyInvokable]
public class Progress<T> : IProgress<T>
{
private readonly SynchronizationContext m_synchronizationContext;
private readonly Action<T> m_handler;
private readonly SendOrPostCallback m_invokeHandlers;
[__DynamicallyInvokable]
public event EventHandler<T> ProgressChanged
{
[__DynamicallyInvokable]
add
{
EventHandler<T> eventHandler = this.ProgressChanged;
EventHandler<T> eventHandler2;
do
{
eventHandler2 = eventHandler;
EventHandler<T> value2 = (EventHandler<T>)Delegate.Combine(eventHandler2, value);
eventHandler = Interlocked.CompareExchange<EventHandler<T>>(ref this.ProgressChanged, value2, eventHandler2);
}
while (eventHandler != eventHandler2);
}
[__DynamicallyInvokable]
remove
{
EventHandler<T> eventHandler = this.ProgressChanged;
EventHandler<T> eventHandler2;
do
{
eventHandler2 = eventHandler;
EventHandler<T> value2 = (EventHandler<T>)Delegate.Remove(eventHandler2, value);
eventHandler = Interlocked.CompareExchange<EventHandler<T>>(ref this.ProgressChanged, value2, eventHandler2);
}
while (eventHandler != eventHandler2);
}
}
[__DynamicallyInvokable]
public Progress()
{
this.m_synchronizationContext = (SynchronizationContext.CurrentNoFlow ?? ProgressStatics.DefaultContext);
this.m_invokeHandlers = new SendOrPostCallback(this.InvokeHandlers);
}
[__DynamicallyInvokable]
public Progress(Action<T> handler) : this()
{
if (handler == null)
{
throw new ArgumentNullException("handler");
}
this.m_handler = handler;
}
[__DynamicallyInvokable]
protected virtual void OnReport(T value)
{
Action<T> handler = this.m_handler;
EventHandler<T> progressChanged = this.ProgressChanged;
if (handler != null || progressChanged != null)
{
this.m_synchronizationContext.Post(this.m_invokeHandlers, value);
}
}
[__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
void IProgress<T>.Report(T value)
{
this.OnReport(value);
}
private void InvokeHandlers(object state)
{
T t = (T)((object)state);
Action<T> handler = this.m_handler;
EventHandler<T> progressChanged = this.ProgressChanged;
if (handler != null)
{
handler(t);
}
if (progressChanged != null)
{
progressChanged(this, t);
}
}
}
}
这篇关于寻找.NET 4.5 Progress T。源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文