新手请教:C# 关于事件定义的问题及使用目的?
public class Core{
public const string FIELD_ID = "id";
public const string FIELD_URL = "url";
public const string FIELD_TITLE = "title";
#region singleton
private Core() {
this._timeoutRetry = Properties.Settings.Default.nudTimeoutRetry;
ThreadPool.SetMaxThreads(this._maxThreadCount, this._maxThreadCount);
this._conn = new OleDbConnection(Properties.Settings.Default.databaseConnectionString);
this._adapter = new OleDbDataAdapter("SELECT * FROM item", this._conn);
OleDbCommandBuilder _builder = new OleDbCommandBuilder(this._adapter);
this._connMysql = new MySqlConnection(
string.Format("host={0};database={1};uid={2};pwd={3};charset=utf8", this._remoteHost, this._remoteDb, this._remoteUser, this._remotePwd));
}
private static Core _instance;
public static Core Instance {
get {
if (_instance == null) {
_instance = new Core();
}
return _instance;
}
}
#endregion
/// 所有线程状态
/// </summary>
private Queue<RequestState> _queueStates = new Queue<RequestState>();
/// <summary>
/// 默认编码
/// </summary>
private Encoding _defaultEncoding = Encoding.UTF8;
#region 事件
// 记录状态发生改变
public delegate void StatusChangeDelegate(LocalData.itemRow row);
public event StatusChangeDelegate OnStatusChange;
//// 事件:工作状态发生改变
//public delegate void OnWorkerStatusChangeDelegate(WorkerStatuses status);
//public event OnWorkerStatusChangeDelegate OnWorkerStatusChange;
#endregion
以下是问题:
1、 这句 private Core() 为什么要定义成private?
2、语句“public static Core Instance”是构造函数吗?
Instance为什么要加static?
3、连接是远程MYSQL数据库,为什么要加charset=utf8?C#支持哪些字符集?
4、这下面两句什么意思?
private Queue<RequestState> _queueStates = new Queue<RequestState>();
private Encoding _defaultEncoding = Encoding.UTF8;
5、事件是什么意思, 程序中也没有找到OnStatusChange的定义,下面这句怎么理解啊?
上面这些事件代码是机器添加的,还是手工添加的啊?
public event StatusChangeDelegate OnStatusChange;
[ 本帖最后由 mtg 于 2013-4-16 18:23 编辑 ]