C# 一些自己需要知道的事情

  [ThreadStaticAttribute]
    static int currId;
double dValue = unchecked( (double)nValue));



Thread.Sleep和Timer性能比较

应该是Thread.Sleep比较好

http://www.cnblogs.com/dataflow/archive/2009/03/11/1408731.html


lambda的一个应用

  1. Thread t1 = new Thread(() =>
  2.     {
  3.         Thread.Sleep(1000);
  4.         Thread t = Thread.CurrentThread;
  5.         Console.WriteLine("Name: " + t.Name);
  6.         Console.WriteLine("ManagedThreadId: " + t.ManagedThreadId);
  7.         Console.WriteLine("State: " + t.ThreadState);
  8.         Console.WriteLine("Priority: " + t.Priority);
  9.         Console.WriteLine("IsBackground: " + t.IsBackground);
  10.         Console.WriteLine("IsThreadPoolThread: " + t.IsThreadPoolThread);
  11.     })
  12.     {
  13.         Name = "Thread1",
  14.         Priority = ThreadPriority.Highest
  15.     };



多线程与并行

http://www.pin5i.com/showtopic-26814.html



那么,我们如何知道线程池中的线程都运行结束了呢,可以想到上文用过的Monitor结构:

  1. Stopwatch sw = Stopwatch.StartNew();
  2. for (int i = 0; i < totalThreads; i++)
  3. {
  4.     ThreadPool.QueueUserWorkItem(o =>
  5.     {
  6.         Thread.Sleep(1000);
  7.         int a, b;
  8.         ThreadPool.GetAvailableThreads(out a, out b);
  9.         Console.WriteLine(string.Format("({0}/{1}) #{2} : {3}", a, b, Thread.CurrentThread.ManagedThreadId, DateTime.Now.ToString("mm:ss")));
  10.         lock (locker)
  11.         {
  12.             runningThreads--;
  13.             Monitor.Pulse(locker);
  14.         }

  15.     });
  16. }

  17. lock (locker)
  18. {
  19.     while (runningThreads > 0)
  20.         Monitor.Wait(locker);
  21. }

  22. Console.WriteLine(sw.ElapsedMilliseconds);
  23. Console.ReadLine();
复制代码



界面假死的解决方法:

http://www.pin5i.com/showtopic-26820.html


LINQ 比较自定义的类型,很有用!

http://www.cnblogs.com/tianfan/archive/2010/03/06/how-to-use-linq-methods-to-compare-objects-of-custom-types.html


并行很好的文章

http://blog.csdn.net/xuzhongxuan/article/details/6288105


关于Task的,还涉及到异常

http://www.cnblogs.com/yanyangtian/archive/2010/06/01/1749199.html

d:/projects/TaskTest 就是里面的一个例子




int[] 的类型是  int[]

父类型是 Array

IsArray

GetElementType 将返回 int

posted on 2011-12-30 11:20  norsd  阅读(132)  评论(0编辑  收藏  举报

导航