c# 相关知识
名词
Handle句柄
门把手,相当操作对象的钥匙或指令
Enable使能
使之能够,能解为开关
多线程
Thread
//线程暂停3000ms
Thread.Sleep(3000);
Task
Task.Run(()=>{
//匿名委托,这里是要执行的程序
});
Async&Await
public static async Task mainrun()
{
var account = new Account(1000);
var tasks = new Task[100];
for (int i = 0; i < tasks.Length; i++)
{
tasks[i] = Task.Run(() => Update(account));
}
await Task.WhenAll(tasks);
Console.WriteLine($"Account's balance is {account.GetBalance()}");
// Output:
// Account's balance is 2000
}
ContinueWith
WhenAll
WaitAll
ManualResetEvent
ManualResetEvent m;//申明暂停线程用
m = new ManualResetEvent(true);//实例化暂停线程用
m.Reset();//复位
m.Set();//置位
m.WaitOne();//暂停点
委托&事件
Action 无返回值委托
无返回值无参委托
Action action = new Action(Accomplish);
Fun<> 有返回值委托
最后一个int为返回值类型
Func<int, int, int> bop = new Func<int, int, int>(SomeMethod);
IAsyncResult result = bop.BeginInvoke(1, 2, null, null);
Invoke
确认委托不为空再执行
this?.invoke();
BeginInvoke
this.BeginInvoke(() => result.AppendText(str));
其他常用
Lock
Stopwatch
计时器
//开始计时
Stopwatch sw = Stopwatch.StartNew();
//结束计时
sw.Stop();


浙公网安备 33010602011771号