??????3????????÷????????????????????????????????????????????????????????????Χ???????????????????÷????£?
public class CSpiderCtrl
{
//?????????????????????
static Semaphore semaphore;
public static void Run()
{
//1. ???? SuperLCBB????????
var oClient = new ServiceReference_SuperLCBB.SOAServiceClient();
//2.??????????new??????????255?????????????????????ж???????????????????????????????????
semaphore = new Semaphore(250?? 255);
CLogService.Instance.Debug("??????????...");
_TestBedGo(oClient);
}
//??ж????????
private static void _TestBedGo(ServiceReference_SuperLCBB.SOAServiceClient oClient)
{
List<string> lstExceptPDUs = new List<string>(){
"SUPERLABEXP"
};
var oTestBedRes = oClient.GetTestBedExceptSomePDU(lstExceptPDUs.ToArray()?? true);
if (CKVRes.ERRCODE_SUCCESS != oTestBedRes.ErrCode)
{
CLogService.Instance.Error("xxx");
return;
}
var lstTestBed = oTestBedRes.ToDocumentsEx();
System.Threading.Tasks.Parallel.ForEach(lstTestBed?? (oTestBed) =>
{
//??ζ?255??????????255???????????????????????????
semaphore.WaitOne();
//CLogService.Instance.Info("?????????????" + oTestBed[TBLTestBed.PROP_NAME]);
//Thread.Sleep(2000);
var strTestBedName = oTestBed[TBLTestBed.PROP_NAME] as string;
var strSuperDevIP = oTestBed[TBLTestBed.PROP_SUPERDEVIP] as string;
var strTestBedGID = oTestBed[TBLTestBed.PROP_GID] as string;
var strPdu = oTestBed[TBLTestBed.PROP_PDUGID] as string;
Thread.Sleep(new Random().Next(1000?? 5000));
var oGetRootDevicesByTestBedGIDRes = oClient.GetRootDevicesByTestBedGID(strTestBedGID);
CLogService.Instance.Debug(strPdu + "——?????Name??" + strTestBedName + "???");
Stopwatch sp = new Stopwatch();
sp.Start();
if (oGetRootDevicesByTestBedGIDRes.ErrCode != CKVRes.ERRCODE_SUCCESS || oGetRootDevicesByTestBedGIDRes.Documents.Count < 2)
{
CLogService.Instance.Debug("shit -- 3??????в????Name??" + strTestBedName + "2?????0");
//?????????????????return ????????????????????????????????
semaphore.Release();
return;
}
var strXML = oGetRootDevicesByTestBedGIDRes.Documents[0];
var strExeName = oGetRootDevicesByTestBedGIDRes.Documents[1];
//var strExeName = "RateSpider";
var oSuperDevClient = new SuperDevClient(CSuperDev.ENDPOINT?? string.Format(CSuperDev.SuperDevURL?? strSuperDevIP));
try
{
oSuperDevClient.IsOK();
}
catch (Exception)
{
CLogService.Instance.Error("?????Name??" + strTestBedName + "??????????");
semaphore.Release();
return;
}
//2.3.1.????SuperDev.Server(SuperDevIP)??????Run(XML??Exename)
var oRunExeRes = new CKVRes();
try
{
oRunExeRes = oSuperDevClient.RunExeEx(strExeName?? false?? new string[] { strXML });
}
catch
{
//CLogService.Instance.Debug("?????Name??" + strTestBedName + "??:" + ex.Message);
}
sp.Stop();
CLogService.Instance.Debug(strPdu + "——?????Name??" + strTestBedName + "??????" + sp.Elapsed);
//???????????????????
semaphore.Release();
});
}
}
??????????Semaphore??????????????????????????????趨??System.Threading.Tasks.Parallel.ForEach??????????????lstTestBed.Length??????????????飬????????
????foreach(var oTestbed in lstTestBed)
????{
????Thread oThread=new Thread(new ThreadStart({   ...}));
????}
??????4?? ????????滹????????????SpinWait?????????????????????????????????????????????У??????????????????????????????÷???
????public static void SpinUntil(Func<bool> condition);
????public static bool SpinUntil(Func<bool> condition?? int millisecondsTimeout);
????public static bool SpinUntil(Func<bool> condition?? TimeSpan timeout);
????????????????????????????????????????????????????漲??????????з????????????????????????
SpinWait.SpinUntil(() =>
{
bIsworking = m_oClient.isworking(new isworking()).result;
return bIsworking == false;
}?? 600000);
//???????10?????????????????
if (bIsworking)
{
oRes.ErrCode = "false???????????????10????????????????";
return oRes;
}
??????????ù????????÷??????????????????Щ???л??漰??????????????????????????Щ??????????????ī?????????????????ú?????????Щ???????????????????????????????????????ó?????????