You’ll need a place to hold your current value, in the example I’ve made it to be a local named pageNum
. Inside your loop then, you’ll increment that variable and assign it to the Page
property on the PlayerSearchParameters
object being constructed in its initializer.
If you want the method to wait for the async method to be completed before starting the next iteration of the loop, make the event handler async
and await
the result of the one you’re calling.
private async void button2_Click(object sender, EventArgs e)
{
var pageNum = 0;
while(true) //<-- Insert whatever your real condition is here instead of true
{
var searchParameters = new PlayerSearchParameters
{
Page = ++pageNum,
League = League.BarclaysPremierLeague,
Nation = Nation.England,
Position = Position.CentralForward,
Team = Team.ManchesterUnited
};
await LoginM.SearchItemsAsync(searchParameters);
}
}
If you’re trying to get this behavior without having to click a button first, you could put the body of the method in a handler for the Load
event on your form instead.
solved Update variable on each loop [closed]