开发者

How to add actual wait?

开发者 https://www.devze.com 2023-03-20 04:20 出处:网络
Im currently trying to code very simple thing. what it supposed to do: enter google wait 5 seconds search something.

Im currently trying to code very simple thing.

what it supposed to do:

  1. enter google
  2. wait 5 seconds
  3. 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开发者_C百科 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 Action and a TimeSpan or 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.)


You need to do the work on a seprate thread so it dosent halt the GUI thread.

    Thread worker = new Thread(dowork);
    worker.Start();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号