Im currently trying to code very simple thing.
what it supposed to do:
- enter google
- wait 5 seconds
- search something.
now, the part I cant do is wait.
There is thread sleep etc. but they stop GUI and makes my program unusable.
I can also do it with timers but it isnt very effective way to do it, since in actual app there will be many waits…
Are there anyway to do with it like 2-3 lines of code only, and without stopping GUI?
A timer is exactly what you want here – you want to say, “In 5 seconds, do X” (potentially executing in the UI thread) which is exactly what a timer does for you. If you want to encapsulate that in a single method which you can pass in an
Actionand aTimeSpanor whatever, that’s fine – but a timer is definitely the way to go.(The type of timer you want to use will depend on what thread you want the timer to fire on, etc.)