12,165
社区成员
发帖
与我相关
我的任务
分享
private static int CurrentCount {get;set;}
private static object syncRoot = new Object();
WebService方法体内:
private bool canAccessDb = false;
while (!canAccessDb)
{
if (CurrentCount < n)
{
lock (syncRoot)
{
if (CurrentCount < n)
{
CurrentCount++;
canAccessDb = true;
}
}
if( canAccessDb )
{
查询数据库的操作;
CurrentCount --;
return;
}
}
else
{
Thread.Sleep(100);
}
}