Fiínek Cahů
Fiínek Cahů

Reputation: 67

Run next task after previouse is completed

I want to run next task after task Jaguar.roky() is finished. I have a problem with jaguar.roky() code not finished and next step running.

Public Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles tiskEtiketaBut.Click
    Try

       fileprint.PrintThisfile(filePath)
       Threading.Thread.Sleep(3000)
       SendKeys.Send("{ENTER}")
       'Threading.Thread.Sleep(500)
       Refresh()
       If regCis = "238.044-015" Or regCis = "238.044-025" Or regCis = "238.044-035" Or regCis = "238.044-045" Or regCis = "238.044-115" Or regCis = "238.044-125" Or regCis = "238.044-135" Or regCis = "238.044-145" Or regCis = "238.044-355" Or regCis = "238.044-365" Or regCis = "238.044-455" Or regCis = "238.044-465" Or regCis = "238.045-015" Or regCis = "238.045-025" Or regCis = "238.045-035" Or regCis = "238.045-045" Or regCis = "238.045-355" Or regCis = "238.045-365" Then
          Jaguar.roky() 'Here is a problem
          ButtonIncrement_Click(Nothing, Nothing)  
       Else
          'Pricteni kusu

       End If
   Catch
       MsgBox("Nepodařilo se vytisknout!", , "Chyba"). 
       tiskEtiketaBut.BackColor = Color.DimGray
       tiskEtiketaBut.Enabled = True
    End Try
End sub


Public Class Jaguar

    Public Shared Sub roky()
        Dim rok As Integer
        rok = Year(Now)

        If rok = 2019 Then            
            dny()            
            mesice()           
            SendKeys.Send("{9}")            
            SendKeys.Send("{ENTER}")           
        Else

        End If

    End Sub
End class

Public Sub ButtonIncrement_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim reftext As TextBox = Me.Controls("TextBox4")
        Dim value As Integer

        'Pri naplneni baleneho mnozstvi
        Try
            If Integer.Parse(TextBox4.Text) = Integer.Parse(TextBox3.Text) Then
                MsgBox("Balicí množství naplněno. Nelze zabalit další kus!", , "Upozornění")
            Else
                If Integer.TryParse(TextBox4.Text, value) Then
                    TextBox4.Text = (value + 1).ToString()
                    ''Pokud jde o klasicka svetla , bez tisku 6etikety
                    If Integer.Parse(TextBox4.Text) = Integer.Parse(TextBox3.Text) And (print6 = False) Then

                        evidence_Click(sender, e)
                        System.Threading.Thread.Sleep(100)
                        Zahlaseni.casBox.Text = rozdil.Text
                        Zahlaseni.ShowDialog()
                    End If
                End If
            End If
        Catch
            MsgBox("Operace se nezdařila. Opakujte prosím znovu0.", , "Chyba")
            Return
        End Try
    End Sub

Upvotes: 0

Views: 93

Answers (1)

ADyson
ADyson

Reputation: 61904

You didn't make it totally clear, but I think you're expecting the process triggered by your SendKeys.Send command to be completed before your code continues. Otherwise I can't see how your statement

jaguar.roky() code not finished and next step running.

would make any sense. jaguar.roky() does finish, but it also potentially triggers a separate process when it simulates the Enter keypress. I suspect it's that process which you are concerned about.

The documentation for SendKeys at https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys?view=netframework-4.8#remarks says:

Use SendKeys to send keystrokes and keystroke combinations to the active application. This class cannot be instantiated. To send a keystroke to a class and immediately continue with the flow of your program, use Send. To wait for any processes started by the keystroke, use SendWait.

That last sentence should help you, I think.

Change

SendKeys.Send("{ENTER}")

to

SendKeys.SendWait("{ENTER}")

and your code will wait until the action triggered by the Enter keypress has completed before it moves to the next line.

Upvotes: 1

Related Questions