一、訊息處理中的主要概念“訊息”是在兩台電腦間傳送的資料單位。訊息可以非常簡單,例如只包含文本字串;也可以更複雜,可能包含內嵌物件。訊息被發送到隊列中。“訊息佇列”是在訊息的傳輸過程中儲存訊息的容器。訊息佇列管理器在將訊息從它的源中繼到它的目標時充當中間人。隊列的主要目的是提供路由並保證訊息的傳遞;如果發送訊息時接收者不可用,訊息佇列會保留訊息,直到可以成功地傳遞它。“訊息佇列”是 Microsoft 的訊息處理技術,它在任何安裝了 Microsoft Windows
.NET MessageQueue 類沒有取得訊息佇列中訊息總數的API,用遍曆的方式得到訊息佇列中訊息總數在訊息總數巨大的時候效率很低下,以下辦法可以比較好的解決這個問題。1. 運行環境。 Windows 2003 Server VS2005 安裝訊息佇列服務 2. 添加引用。 如在項目中添加引用。 3. 方法 Code highlighting produced by Actipro CodeHighlighter
非同步呼叫委託的3種方法using System;using System.Collections.Generic;using System.Text;namespace AsyncDelegate{ class Program { delegate int IntIntDelegate(int x);//生明一個委託 int Square(int x) { return x * x; }
1: 建立一個範型類MyList.cspublic class MyList<T> { private static int objCount = 0; public int Count { get { return objCount; } } public MyList() { objCount++; } }2:調用範型類MyList.cs public void MyListShow()
委託是C#中實現事件的基礎,有時候不可避免的要動態建立委託,實際上委託也是一種類型:System.Delegate,所有的委託都是從這個類派生的System.Delegate提供了一些靜態方法來動態建立一個委託,比如一個委託:namespace TestSpace { delegate string TestDelegate(string value); public class TestClass { public TestClass() { }
下面這段程式示範了Timer類的用法。using System;using System.Threading;class TimerExampleState{ public int counter = 0; public Timer tmr;}class App{ public static void Main() { TimerExampleState s = new TimerExampleState(); //建立代理對象TimerCal