private static Semaphore semaphore;
void CreateOrder(IEnumerable list)
{
if (semaphore==null) semaphore = new Semaphore(20, 30);
foreach (var item in list)
{
semaphore.WaitOne();
try
{
Action action = () =>
{
//具体业务逻辑
//释放信号量必须放在具体的action里面
semaphore.Release();
};
action.BeginInvoke(null, null);
}
catch (Exception e)
{
//
}
}
}