现在的位置: 首页 > 综合 > 正文

我的CCR之旅(4):倾听CCR的心跳声–Dispatcher(基础篇)

2012年12月12日 ⁄ 综合 ⁄ 共 6618字 ⁄ 字号 评论关闭

    PS:前段时间稍微有些累,故暂停了本系列文章,今天状态开始恢复,继续旅程。

    之前几章已经整体把CCR介绍了一下,为了更好地了解和使用CCR,接下来几章我将逐一介绍CCR内重要的几个类,本章要介绍的是CCR的心脏Dispatcher。

    在我们使用Dispatcher的时候,最常用到的就是他的构造函数和资源释放函数了,因此本节,先介绍这2类函数,其他的函数因为涉及到DispatcherQueue等内部的运作机制,属于CCR内部的运作调度机制,留待前面这些基础知识交代完毕后再另起一篇细说。

Dispatcher内含的方法、属性预览
public sealed class Dispatcher : IDisposable
{
    
// 1、构造函数
    public Dispatcher();
    
public Dispatcher(int threadCount, string threadPoolName);
    
public Dispatcher(int threadCount, ThreadPriority priority,
            
bool useBackgroundThreads, string threadPoolName);
    
public Dispatcher(int threadCount, ThreadPriority priority,
            DispatcherOptions options, 
string threadPoolName);
    
public Dispatcher(int threadCount, ThreadPriority priority,
            DispatcherOptions options,
            ApartmentState threadApartmentState,
            
string threadPoolName);

    // 2、资源释放函数
    public void Dispose();

    // 3、属性
    public static ICollection<Causality> ActiveCausalities { get; }
    
public List<DispatcherQueue> DispatcherQueues { get; }
    
public string Name { getset; }
    
public DispatcherOptions Options { getset; }
    
public int PendingTaskCount { getset; }
    
public long ProcessedTaskCount { getset; }
    
public static int ThreadsPerCpu { getset; }
    
public int WorkerThreadCount { getset; }

    // 4、因果关系函数
    public static void AddCausality(Causality causality);
    
public static void AddCausalityBreak();
    
public static void ClearCausalities();
    
public static bool RemoveCausality(Causality causality);
    
public static bool RemoveCausality(string name);
}

一、构造函数
     Dispatcher给我们提供了5个构造函数,其实是为了方便大家使用而对一个构造函数做的封装,我们看看具体的实现代码(我在关键的地方都加上了中文的注释):

5个构造函数(反编译得到,仅参考)

抱歉!评论已关闭.