0

I can't figure out how to make system to wait 10 secounds without make him to sleep (I want to make only timer2 to wait 10 seconds and after it, to start work. I tried System.Threading.Thread.Sleep(10000) but this code make all app to sleap. Here is the code from timer2

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick '1214x727 Dim procinstall As Boolean = Process.GetProcesses().Any(Function(p) p.ProcessName.Contains("ErrorFixer")) If procinstall = True Then SetCursorPos(1214, 727) mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) 'Invoke mouse down event mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) 'Invoke mouse up event mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) 'Invoke mouse down event mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) 'Invoke mouse up event Timer2.Stop() Label3.Text = "Installing" End If End Sub 

After If procinstall = True Then, I want to put that code to wait until cursor will go to that position and mouse will click.

Thanks.

3
  • Sleep pauses the whole thread. If you are using only one thread, the whole application would be paused. You should look at multi-threading. Commented Mar 3, 2014 at 16:28
  • You should look into using the multi-threading. BUT are you sure you have the timer enabled... have you setup a break to make sure it is not something simple? Also could give you a chance to look at the values to make sure it is passing through properly. Commented Mar 3, 2014 at 16:31
  • On the other hand, Neolisk is right. With a timer there is an immediate and practical solution for your problem: affect the Interval property. Actually using Sleep when you have a timer running does not seem required... Commented Mar 3, 2014 at 16:37

1 Answer 1

3

Set the Timer's interval to 10000. Handle Elapsed event (for Timers.Timer).

EDIT: If you are using a Timer control on a form, the event is called Tick.

Sign up to request clarification or add additional context in comments.

4 Comments

I set the interval but I still don't get how to use elapsed event. I should declare it inside the timer sub or then I declare timer2.enabled = true?
@terror: Make sure the timer is enabled. You can use Form_Load or set as a result of a user action (or another event). Actually, for windows timer control, the event is called Tick. Double click on a timer control when it's placed on a form, it will generate the signature for you. Then just place the code you want in it.
Then I put interval to 10.000, it set interval between recheck of code (for exemple if I have if statement, timer will check this statement every 10.000 until timer2.stop or timer2.enabled = false is called) but I want to set this interval between If statement and SetCursorPos.
@terror: Sure, just set Interval and Enabled = True after your If statement. Make sure it's Enabled = False before the If statement.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.