welcome to Qijie's Blog 薛其杰

随笔分类 -  .NET Framework

使用Semaphore(旗语)控制线程同步
摘要:今天同事做培训讲到了线程同步的方法, 其中一个就是用到Semaphore。 Semaphore可以用在不同进程之间的线程同步, 若是在单进程中的线程同步, 使用lock或是Monitor就足够了。 正如其名 旗语就是存在多个任务, 每个任务上都插一个小旗作为互斥信号, 当有一个线程去访问该任务时, 就拔掉小旗 以示其他线程不能访问, 访问完成后再插回小旗使其他线程可以访问。Demo:代码Code ... 阅读全文
posted @ 2009-11-28 11:17 零点零一 阅读(592) 评论(0) 推荐(0)
线程池
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;namespace ConsoleApplication1{ class Print { public void printNumbers() { Monitor.Enter(this); ... 阅读全文
posted @ 2009-10-22 09:04 零点零一 阅读(198) 评论(0) 推荐(0)
线程同步lock and monitor
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;namespace ConsoleApplication1{ class Print { public void printNumbers() { Monitor.Enter(this); ... 阅读全文
posted @ 2009-10-22 09:03 零点零一 阅读(189) 评论(0) 推荐(0)
委托异步调用 C#
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Runtime.Remoting.Messaging; //AsyncResult需要此命名空间 using System.Threading; //Thread.Sleep(5000)需要此命名空间names... 阅读全文
posted @ 2009-10-16 09:06 零点零一 阅读(320) 评论(0) 推荐(0)
应用程序域编程
摘要:Imports System.AppDomainImports System.ReflectionModule Module1 Sub Main() Dim _domain As AppDomain = AppDomain.CurrentDomain() Dim _assemblys() As Assembly = _domain.GetAssemblies() For Each a As Ass... 阅读全文
posted @ 2009-10-15 09:04 零点零一 阅读(173) 评论(0) 推荐(0)
进程诊断与编程
摘要:Imports System.DiagnosticsModule Module1 Sub Main() Dim _p As Process = Process.Start("iexplore", "http://www.g.cn") Dim _threads As ProcessThreadCollection = _p.Threads Console.WriteLine("Process:{0}... 阅读全文
posted @ 2009-10-15 09:01 零点零一 阅读(188) 评论(0) 推荐(0)
委托异步调用 VB
摘要:Imports System.DelegateImports System.ThreadingDelegate Function BinaryOp(ByVal arg1 As Integer, ByVal arg2 As Integer) As IntegerModule Module1 Sub Main() Dim b As BinaryOp = AddressOf Add Dim IAR As... 阅读全文
posted @ 2009-10-15 08:59 零点零一 阅读(298) 评论(0) 推荐(0)