양식 응용 프로그램을 작성하고 while 루프에서 while 루프를 반복하면서 결과를 찾을 때까지 누릅니다. 그러나이 루핑은 일부 서버를 요청하고 있습니다. 이 요청을 최대 5 건의 요청에 1 분 안에 집중시키고 싶습니다. 따라서 새로운 분이 시작될 때까지 잠 들어있는 논리가 필요합니다. 누군가 나를 도울 수 있습니까?win form 응용 프로그램에서 분당 5 건의 요청을 처리하는 방법
public int RPMCounter { get; set; }
private async void SearchCheapestAuction()
{
bool foundItem = false;
textBoxLogging.Clear();
textBoxLogging.Text += System.Environment.NewLine + "start";
// 1 stay loooping till you found this item for the buynowprice
while (!foundItem)
{
// 2 check if this is request number 5 in one minute
if (RPMCounter <= 5)
{
// 3 increase counter
RPMCounter++;
// 4 set searchparameters
var searchParametersPlayers = new PlayerSearchParameters
{
MaxBid = (uint)Convert.ToInt16(textBoxMaxStartPrice.Text),
MinBid = (uint)Convert.ToInt16(textBoxMinStartPrice.Text),
MaxBuy = (uint)Convert.ToInt16(textBoxMaxBuyNow.Text),
MinBuy = (uint)Convert.ToInt16(textBoxMinBuyNow.Text)
};
// 5 run search query
var searchResponse = await client.SearchAsync(searchParametersPlayers);
// 8 check if the search found any results
if (searchResponse.AuctionInfo.Count > 0)
{
// 9 buy this player for the buy now price
var auctionResponse = await client.PlaceBidAsync(searchResponse.AuctionInfo.First(), searchResponse.AuctionInfo.First().BuyNowPrice);
// 10 stop searching/buying, I found my item for the right price
return;
}
}
else
{
// 11 I access the 5 rpm, sleep till the next minutes begin and go search again?
return;
}
}
textBoxLogging.Text += System.Environment.NewLine + "finished";
}
}
안녕하세요, Matt, 답변 해 주셔서 대단히 감사합니다. 네, 구현 목표 : 1 분당 5 개로 제한합니다. 12 초 간격으로 타이머로 제발 나를 위해 코드에 몇 가지 예가 있습니까? – Ola
이 (가) 게시물을 편집하고 일부 코드를 추가했습니다. 잘하면 도움이됩니다. –