Force loop to wait for an event

前端 未结 3 1614
梦毁少年i
梦毁少年i 2020-12-12 05:07

I am trying to write a method that goes through a list of items - for each one adds it to a form, then waits for the user to input some data and click a button. However I ha

3条回答
  •  [愿得一人]
    2020-12-12 05:43

    There are ways of doing this using signalling if you're also using async/await - you could await a task which is completed by the button being clicked for example - but in general you should think about user interfaces in a more event-driven way.

    Instead of having your foreach loop here, keep an index into the collection for which item is being displayed, and advance it each time the button is clicked. (Remember to check whether or not there are more items to display, of course.)

提交回复
热议问题