我有用於讀取QR碼的while(true)循環。我想在讀取有效QR碼時暫停循環,然後執行某些操作(在數據庫中插入值),然後繼續循環讀取其他QR碼。我用休息和繼續,但打破走出循環,繼續跳到我的代碼,我不想them.I'm與事先C#和SQL server.Thanks工作如何暫停循環一段時間,然後再繼續使用C#?
編輯:我不在閱讀Qr代碼時沒有任何問題我的代碼工作正常,我只需要知道如何暫停循環並執行某些操作,然後繼續循環。下面是代碼。我可以停止,同時用if語句
while ((int)(1) != 0)
{
ho_Image.Dispose();
HOperatorSet.GrabImage(out ho_Image, hv_AcqHandle);
HOperatorSet.DispObj(ho_Image, HWindow);
operation(ho_Image, hv_Type1, hv_Type2, hv_Num1ecc, hv_Num2qr, hv_Qr, hv_Ecc,
HWindow, hv_Timeoutqr, hv_Timeoutecc, out hv_DecodedDataStrings1,
out hv_DecodedDataStrings2, out hv_DataCodeHandle1, out hv_DataCodeHandle2,
out hv_foundecc, out hv_foundqr);
hv_Qr = 0;
hv_Ecc = 0;
//MessageBox.Show(" QR NuM : " + this.QRNumber);
//MessageBox.Show("ECC Number : " + this.ECCNumber);
if (this.QRNumber == QRNum && this.ECCNumber == ECCNum)
{
foreach (string qr in this.QRValue)
{
MessageBox.Show(" QR value : " + qr);
}
foreach (string ecc in this.ECCValue)
{
MessageBox.Show("ECC value : " + ecc);
}
}
}
添加異步任務,並等待數據保存到數據庫中。 – raichiks
你看看「yield」用法嗎,我想它可以幫你 –
如果我錯了,請糾正我,但如果你的代碼讀取代碼不是異步的,那麼其他命令將不會被執行,直到完成。 。 – Jelman