Continue for loop if a file is created in VB.NET












0















I'm using a COM interface to export animations from a third-party program. I'm sending an exporting COM command with script from my tool with a shell command.



There's a problem with when I send the animation export command to the third-party tool. It starts to export, but my tool is sending a second animation export command while the last one is not finished. How can I prevent from this situation?



I'd like to sending my shell command from the for loop after the file was created.



My code is like below.



Private Sub tlbCheckSolveEvaCtrl_exportmodeshape_Click(sender As Object, e As EventArgs) Handles tlbCheckSolveEvaCtrl_exportmodeshape.Click
Try
Dim strArgument As String

Dim strfilePathEV As String
Dim strfilePathANI As String
Dim strfilePathPIC As String

strfilePathEV = strProjMdlDir & My.Settings.txtCheckSolverOuputDir & strProjMdlName & ".ev.sbr"
strfilePathANI = strProjMdlDir & "" & My.Settings.txtProjDirDOC & "" & My.Settings.txtProjDirANI & ""
strfilePathPIC = strProjMdlDir & "" & My.Settings.txtProjDirDOC & "" & My.Settings.txtProjDirPIC & ""

For i As Integer = 0 To dgvCheckSolveEva.RowCount - 1
strArgument = strfilePathEV & " " & _
strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
i
Shell(My.Settings.txtSpckDir & "simpack-post.exe -s qs_mode_shape.qs " & strArgument)
Next


Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub


I'd like to continue my for loop if strfilePathANI & strProjMdlName & "_" & i & ".mpg", the animation file was created, so I can start to export the next one.










share|improve this question





























    0















    I'm using a COM interface to export animations from a third-party program. I'm sending an exporting COM command with script from my tool with a shell command.



    There's a problem with when I send the animation export command to the third-party tool. It starts to export, but my tool is sending a second animation export command while the last one is not finished. How can I prevent from this situation?



    I'd like to sending my shell command from the for loop after the file was created.



    My code is like below.



    Private Sub tlbCheckSolveEvaCtrl_exportmodeshape_Click(sender As Object, e As EventArgs) Handles tlbCheckSolveEvaCtrl_exportmodeshape.Click
    Try
    Dim strArgument As String

    Dim strfilePathEV As String
    Dim strfilePathANI As String
    Dim strfilePathPIC As String

    strfilePathEV = strProjMdlDir & My.Settings.txtCheckSolverOuputDir & strProjMdlName & ".ev.sbr"
    strfilePathANI = strProjMdlDir & "" & My.Settings.txtProjDirDOC & "" & My.Settings.txtProjDirANI & ""
    strfilePathPIC = strProjMdlDir & "" & My.Settings.txtProjDirDOC & "" & My.Settings.txtProjDirPIC & ""

    For i As Integer = 0 To dgvCheckSolveEva.RowCount - 1
    strArgument = strfilePathEV & " " & _
    strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
    i
    Shell(My.Settings.txtSpckDir & "simpack-post.exe -s qs_mode_shape.qs " & strArgument)
    Next


    Catch ex As Exception
    MsgBox(ex.Message)
    End Try
    End Sub


    I'd like to continue my for loop if strfilePathANI & strProjMdlName & "_" & i & ".mpg", the animation file was created, so I can start to export the next one.










    share|improve this question



























      0












      0








      0


      0






      I'm using a COM interface to export animations from a third-party program. I'm sending an exporting COM command with script from my tool with a shell command.



      There's a problem with when I send the animation export command to the third-party tool. It starts to export, but my tool is sending a second animation export command while the last one is not finished. How can I prevent from this situation?



      I'd like to sending my shell command from the for loop after the file was created.



      My code is like below.



      Private Sub tlbCheckSolveEvaCtrl_exportmodeshape_Click(sender As Object, e As EventArgs) Handles tlbCheckSolveEvaCtrl_exportmodeshape.Click
      Try
      Dim strArgument As String

      Dim strfilePathEV As String
      Dim strfilePathANI As String
      Dim strfilePathPIC As String

      strfilePathEV = strProjMdlDir & My.Settings.txtCheckSolverOuputDir & strProjMdlName & ".ev.sbr"
      strfilePathANI = strProjMdlDir & "" & My.Settings.txtProjDirDOC & "" & My.Settings.txtProjDirANI & ""
      strfilePathPIC = strProjMdlDir & "" & My.Settings.txtProjDirDOC & "" & My.Settings.txtProjDirPIC & ""

      For i As Integer = 0 To dgvCheckSolveEva.RowCount - 1
      strArgument = strfilePathEV & " " & _
      strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
      i
      Shell(My.Settings.txtSpckDir & "simpack-post.exe -s qs_mode_shape.qs " & strArgument)
      Next


      Catch ex As Exception
      MsgBox(ex.Message)
      End Try
      End Sub


      I'd like to continue my for loop if strfilePathANI & strProjMdlName & "_" & i & ".mpg", the animation file was created, so I can start to export the next one.










      share|improve this question
















      I'm using a COM interface to export animations from a third-party program. I'm sending an exporting COM command with script from my tool with a shell command.



      There's a problem with when I send the animation export command to the third-party tool. It starts to export, but my tool is sending a second animation export command while the last one is not finished. How can I prevent from this situation?



      I'd like to sending my shell command from the for loop after the file was created.



      My code is like below.



      Private Sub tlbCheckSolveEvaCtrl_exportmodeshape_Click(sender As Object, e As EventArgs) Handles tlbCheckSolveEvaCtrl_exportmodeshape.Click
      Try
      Dim strArgument As String

      Dim strfilePathEV As String
      Dim strfilePathANI As String
      Dim strfilePathPIC As String

      strfilePathEV = strProjMdlDir & My.Settings.txtCheckSolverOuputDir & strProjMdlName & ".ev.sbr"
      strfilePathANI = strProjMdlDir & "" & My.Settings.txtProjDirDOC & "" & My.Settings.txtProjDirANI & ""
      strfilePathPIC = strProjMdlDir & "" & My.Settings.txtProjDirDOC & "" & My.Settings.txtProjDirPIC & ""

      For i As Integer = 0 To dgvCheckSolveEva.RowCount - 1
      strArgument = strfilePathEV & " " & _
      strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
      i
      Shell(My.Settings.txtSpckDir & "simpack-post.exe -s qs_mode_shape.qs " & strArgument)
      Next


      Catch ex As Exception
      MsgBox(ex.Message)
      End Try
      End Sub


      I'd like to continue my for loop if strfilePathANI & strProjMdlName & "_" & i & ".mpg", the animation file was created, so I can start to export the next one.







      vb.net shell






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday









      Peter Mortensen

      13.8k1987113




      13.8k1987113










      asked Jan 2 at 14:02









      HakanHakan

      15011




      15011
























          1 Answer
          1






          active

          oldest

          votes


















          5














          The best way would be to use the .NET Process class and call the WaitForExit() method in order to wait for simpack-post.exe to close itself.



          Shell() is an outdated function from the VB6-era which exists purely for partial backwards compatibility with that language. It shouldn't be used in new code.



          Basic example:





          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()


          The problem with this of course is that it might block the UI thread and thus cause it to freeze, depending on how long it takes for the process to exit. Therefore we should wrap it in a Task:



          Dim c As Integer = dgvCheckSolveEva.RowCount - 1

          Task.Run( _
          Sub()
          For i As Integer = 0 To c
          strArgument = strfilePathEV & " " & _
          strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
          i

          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()
          Next
          End Sub _
          )


          Just note that you cannot directly access the UI from within the task. If you want to do so you need to Invoke.






          EDIT:



          If you are targeting .NET Framework 3.5 or lower, or using VS 2008 or lower, tasks aren't available and we have to resort to using regular threads and/or regular methods instead of lamba expressions.



          Note that the same rules apply, though - you cannot access the UI without invoking.



          .NET 3.5 (or lower) using VS 2010 (and higher):



          Dim c As Integer = dgvCheckSolveEva.RowCount - 1

          Dim t As New Thread( _
          Sub()
          For i As Integer = 0 To c
          strArgument = strfilePathEV & " " & _
          strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
          i

          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()
          Next
          End Sub _
          )
          t.IsBackground = True
          t.Start()


          .NET 3.5 (or lower) using VS 2008 (or lower):



          Private Sub tlbCheckSolveEvaCtrl_exportmodeshape_Click(sender As Object, e As EventArgs) Handles tlbCheckSolveEvaCtrl_exportmodeshape.Click

          ...your code...

          Dim c As Integer = dgvCheckSolveEva.RowCount - 1
          Dim t As New Thread(New ParameterizedThreadStart(AddressOf ExportAnimationsThread))
          t.IsBackground = True
          t.Start(c)

          ...your code...
          End Sub

          Private Sub ExportAnimationsThread(ByVal Count As Integer)
          For i As Integer = 0 To Count
          strArgument = strfilePathEV & " " & _
          strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
          i

          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()
          Next
          End Sub





          share|improve this answer


























          • And you are assuming the OP is targeting > 4.0 framework... :)

            – Çöđěxěŕ
            Jan 2 at 16:52











          • @Çöđěxěŕ : Even though there will always be exceptions, .NET 3.5 and below are fading away more and more these days. So until stated otherwise, yes I am :). But if you're concerned about it I'll edit the answer and include a .NET 3.5 and VS 2008 solution as well.

            – Visual Vincent
            Jan 2 at 17:09













          • Haha, no I am not concerned; great solution BTW.

            – Çöđěxěŕ
            Jan 2 at 17:15








          • 1





            @Çöđěxěŕ : Too late, added it anyway ;). Also, thanks!

            – Visual Vincent
            Jan 2 at 17:22






          • 1





            @Çöđěxěŕ Where is the upvote for the "great solution"?

            – Mary
            Jan 2 at 18:17











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54007710%2fcontinue-for-loop-if-a-file-is-created-in-vb-net%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          5














          The best way would be to use the .NET Process class and call the WaitForExit() method in order to wait for simpack-post.exe to close itself.



          Shell() is an outdated function from the VB6-era which exists purely for partial backwards compatibility with that language. It shouldn't be used in new code.



          Basic example:





          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()


          The problem with this of course is that it might block the UI thread and thus cause it to freeze, depending on how long it takes for the process to exit. Therefore we should wrap it in a Task:



          Dim c As Integer = dgvCheckSolveEva.RowCount - 1

          Task.Run( _
          Sub()
          For i As Integer = 0 To c
          strArgument = strfilePathEV & " " & _
          strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
          i

          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()
          Next
          End Sub _
          )


          Just note that you cannot directly access the UI from within the task. If you want to do so you need to Invoke.






          EDIT:



          If you are targeting .NET Framework 3.5 or lower, or using VS 2008 or lower, tasks aren't available and we have to resort to using regular threads and/or regular methods instead of lamba expressions.



          Note that the same rules apply, though - you cannot access the UI without invoking.



          .NET 3.5 (or lower) using VS 2010 (and higher):



          Dim c As Integer = dgvCheckSolveEva.RowCount - 1

          Dim t As New Thread( _
          Sub()
          For i As Integer = 0 To c
          strArgument = strfilePathEV & " " & _
          strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
          i

          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()
          Next
          End Sub _
          )
          t.IsBackground = True
          t.Start()


          .NET 3.5 (or lower) using VS 2008 (or lower):



          Private Sub tlbCheckSolveEvaCtrl_exportmodeshape_Click(sender As Object, e As EventArgs) Handles tlbCheckSolveEvaCtrl_exportmodeshape.Click

          ...your code...

          Dim c As Integer = dgvCheckSolveEva.RowCount - 1
          Dim t As New Thread(New ParameterizedThreadStart(AddressOf ExportAnimationsThread))
          t.IsBackground = True
          t.Start(c)

          ...your code...
          End Sub

          Private Sub ExportAnimationsThread(ByVal Count As Integer)
          For i As Integer = 0 To Count
          strArgument = strfilePathEV & " " & _
          strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
          i

          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()
          Next
          End Sub





          share|improve this answer


























          • And you are assuming the OP is targeting > 4.0 framework... :)

            – Çöđěxěŕ
            Jan 2 at 16:52











          • @Çöđěxěŕ : Even though there will always be exceptions, .NET 3.5 and below are fading away more and more these days. So until stated otherwise, yes I am :). But if you're concerned about it I'll edit the answer and include a .NET 3.5 and VS 2008 solution as well.

            – Visual Vincent
            Jan 2 at 17:09













          • Haha, no I am not concerned; great solution BTW.

            – Çöđěxěŕ
            Jan 2 at 17:15








          • 1





            @Çöđěxěŕ : Too late, added it anyway ;). Also, thanks!

            – Visual Vincent
            Jan 2 at 17:22






          • 1





            @Çöđěxěŕ Where is the upvote for the "great solution"?

            – Mary
            Jan 2 at 18:17
















          5














          The best way would be to use the .NET Process class and call the WaitForExit() method in order to wait for simpack-post.exe to close itself.



          Shell() is an outdated function from the VB6-era which exists purely for partial backwards compatibility with that language. It shouldn't be used in new code.



          Basic example:





          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()


          The problem with this of course is that it might block the UI thread and thus cause it to freeze, depending on how long it takes for the process to exit. Therefore we should wrap it in a Task:



          Dim c As Integer = dgvCheckSolveEva.RowCount - 1

          Task.Run( _
          Sub()
          For i As Integer = 0 To c
          strArgument = strfilePathEV & " " & _
          strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
          i

          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()
          Next
          End Sub _
          )


          Just note that you cannot directly access the UI from within the task. If you want to do so you need to Invoke.






          EDIT:



          If you are targeting .NET Framework 3.5 or lower, or using VS 2008 or lower, tasks aren't available and we have to resort to using regular threads and/or regular methods instead of lamba expressions.



          Note that the same rules apply, though - you cannot access the UI without invoking.



          .NET 3.5 (or lower) using VS 2010 (and higher):



          Dim c As Integer = dgvCheckSolveEva.RowCount - 1

          Dim t As New Thread( _
          Sub()
          For i As Integer = 0 To c
          strArgument = strfilePathEV & " " & _
          strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
          i

          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()
          Next
          End Sub _
          )
          t.IsBackground = True
          t.Start()


          .NET 3.5 (or lower) using VS 2008 (or lower):



          Private Sub tlbCheckSolveEvaCtrl_exportmodeshape_Click(sender As Object, e As EventArgs) Handles tlbCheckSolveEvaCtrl_exportmodeshape.Click

          ...your code...

          Dim c As Integer = dgvCheckSolveEva.RowCount - 1
          Dim t As New Thread(New ParameterizedThreadStart(AddressOf ExportAnimationsThread))
          t.IsBackground = True
          t.Start(c)

          ...your code...
          End Sub

          Private Sub ExportAnimationsThread(ByVal Count As Integer)
          For i As Integer = 0 To Count
          strArgument = strfilePathEV & " " & _
          strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
          i

          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()
          Next
          End Sub





          share|improve this answer


























          • And you are assuming the OP is targeting > 4.0 framework... :)

            – Çöđěxěŕ
            Jan 2 at 16:52











          • @Çöđěxěŕ : Even though there will always be exceptions, .NET 3.5 and below are fading away more and more these days. So until stated otherwise, yes I am :). But if you're concerned about it I'll edit the answer and include a .NET 3.5 and VS 2008 solution as well.

            – Visual Vincent
            Jan 2 at 17:09













          • Haha, no I am not concerned; great solution BTW.

            – Çöđěxěŕ
            Jan 2 at 17:15








          • 1





            @Çöđěxěŕ : Too late, added it anyway ;). Also, thanks!

            – Visual Vincent
            Jan 2 at 17:22






          • 1





            @Çöđěxěŕ Where is the upvote for the "great solution"?

            – Mary
            Jan 2 at 18:17














          5












          5








          5







          The best way would be to use the .NET Process class and call the WaitForExit() method in order to wait for simpack-post.exe to close itself.



          Shell() is an outdated function from the VB6-era which exists purely for partial backwards compatibility with that language. It shouldn't be used in new code.



          Basic example:





          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()


          The problem with this of course is that it might block the UI thread and thus cause it to freeze, depending on how long it takes for the process to exit. Therefore we should wrap it in a Task:



          Dim c As Integer = dgvCheckSolveEva.RowCount - 1

          Task.Run( _
          Sub()
          For i As Integer = 0 To c
          strArgument = strfilePathEV & " " & _
          strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
          i

          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()
          Next
          End Sub _
          )


          Just note that you cannot directly access the UI from within the task. If you want to do so you need to Invoke.






          EDIT:



          If you are targeting .NET Framework 3.5 or lower, or using VS 2008 or lower, tasks aren't available and we have to resort to using regular threads and/or regular methods instead of lamba expressions.



          Note that the same rules apply, though - you cannot access the UI without invoking.



          .NET 3.5 (or lower) using VS 2010 (and higher):



          Dim c As Integer = dgvCheckSolveEva.RowCount - 1

          Dim t As New Thread( _
          Sub()
          For i As Integer = 0 To c
          strArgument = strfilePathEV & " " & _
          strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
          i

          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()
          Next
          End Sub _
          )
          t.IsBackground = True
          t.Start()


          .NET 3.5 (or lower) using VS 2008 (or lower):



          Private Sub tlbCheckSolveEvaCtrl_exportmodeshape_Click(sender As Object, e As EventArgs) Handles tlbCheckSolveEvaCtrl_exportmodeshape.Click

          ...your code...

          Dim c As Integer = dgvCheckSolveEva.RowCount - 1
          Dim t As New Thread(New ParameterizedThreadStart(AddressOf ExportAnimationsThread))
          t.IsBackground = True
          t.Start(c)

          ...your code...
          End Sub

          Private Sub ExportAnimationsThread(ByVal Count As Integer)
          For i As Integer = 0 To Count
          strArgument = strfilePathEV & " " & _
          strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
          i

          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()
          Next
          End Sub





          share|improve this answer















          The best way would be to use the .NET Process class and call the WaitForExit() method in order to wait for simpack-post.exe to close itself.



          Shell() is an outdated function from the VB6-era which exists purely for partial backwards compatibility with that language. It shouldn't be used in new code.



          Basic example:





          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()


          The problem with this of course is that it might block the UI thread and thus cause it to freeze, depending on how long it takes for the process to exit. Therefore we should wrap it in a Task:



          Dim c As Integer = dgvCheckSolveEva.RowCount - 1

          Task.Run( _
          Sub()
          For i As Integer = 0 To c
          strArgument = strfilePathEV & " " & _
          strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
          i

          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()
          Next
          End Sub _
          )


          Just note that you cannot directly access the UI from within the task. If you want to do so you need to Invoke.






          EDIT:



          If you are targeting .NET Framework 3.5 or lower, or using VS 2008 or lower, tasks aren't available and we have to resort to using regular threads and/or regular methods instead of lamba expressions.



          Note that the same rules apply, though - you cannot access the UI without invoking.



          .NET 3.5 (or lower) using VS 2010 (and higher):



          Dim c As Integer = dgvCheckSolveEva.RowCount - 1

          Dim t As New Thread( _
          Sub()
          For i As Integer = 0 To c
          strArgument = strfilePathEV & " " & _
          strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
          i

          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()
          Next
          End Sub _
          )
          t.IsBackground = True
          t.Start()


          .NET 3.5 (or lower) using VS 2008 (or lower):



          Private Sub tlbCheckSolveEvaCtrl_exportmodeshape_Click(sender As Object, e As EventArgs) Handles tlbCheckSolveEvaCtrl_exportmodeshape.Click

          ...your code...

          Dim c As Integer = dgvCheckSolveEva.RowCount - 1
          Dim t As New Thread(New ParameterizedThreadStart(AddressOf ExportAnimationsThread))
          t.IsBackground = True
          t.Start(c)

          ...your code...
          End Sub

          Private Sub ExportAnimationsThread(ByVal Count As Integer)
          For i As Integer = 0 To Count
          strArgument = strfilePathEV & " " & _
          strfilePathANI & strProjMdlName & "_" & i & ".mpg" & " " & _
          i

          Dim filePath As String = Path.Combine(My.Settings.txtSpckDir, "simpack-post.exe")
          Process.Start(filePath, "-s qs_mode_shape.qs " & strArgument).WaitForExit()
          Next
          End Sub






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 2 at 17:21

























          answered Jan 2 at 15:13









          Visual VincentVisual Vincent

          15.5k52052




          15.5k52052













          • And you are assuming the OP is targeting > 4.0 framework... :)

            – Çöđěxěŕ
            Jan 2 at 16:52











          • @Çöđěxěŕ : Even though there will always be exceptions, .NET 3.5 and below are fading away more and more these days. So until stated otherwise, yes I am :). But if you're concerned about it I'll edit the answer and include a .NET 3.5 and VS 2008 solution as well.

            – Visual Vincent
            Jan 2 at 17:09













          • Haha, no I am not concerned; great solution BTW.

            – Çöđěxěŕ
            Jan 2 at 17:15








          • 1





            @Çöđěxěŕ : Too late, added it anyway ;). Also, thanks!

            – Visual Vincent
            Jan 2 at 17:22






          • 1





            @Çöđěxěŕ Where is the upvote for the "great solution"?

            – Mary
            Jan 2 at 18:17



















          • And you are assuming the OP is targeting > 4.0 framework... :)

            – Çöđěxěŕ
            Jan 2 at 16:52











          • @Çöđěxěŕ : Even though there will always be exceptions, .NET 3.5 and below are fading away more and more these days. So until stated otherwise, yes I am :). But if you're concerned about it I'll edit the answer and include a .NET 3.5 and VS 2008 solution as well.

            – Visual Vincent
            Jan 2 at 17:09













          • Haha, no I am not concerned; great solution BTW.

            – Çöđěxěŕ
            Jan 2 at 17:15








          • 1





            @Çöđěxěŕ : Too late, added it anyway ;). Also, thanks!

            – Visual Vincent
            Jan 2 at 17:22






          • 1





            @Çöđěxěŕ Where is the upvote for the "great solution"?

            – Mary
            Jan 2 at 18:17

















          And you are assuming the OP is targeting > 4.0 framework... :)

          – Çöđěxěŕ
          Jan 2 at 16:52





          And you are assuming the OP is targeting > 4.0 framework... :)

          – Çöđěxěŕ
          Jan 2 at 16:52













          @Çöđěxěŕ : Even though there will always be exceptions, .NET 3.5 and below are fading away more and more these days. So until stated otherwise, yes I am :). But if you're concerned about it I'll edit the answer and include a .NET 3.5 and VS 2008 solution as well.

          – Visual Vincent
          Jan 2 at 17:09







          @Çöđěxěŕ : Even though there will always be exceptions, .NET 3.5 and below are fading away more and more these days. So until stated otherwise, yes I am :). But if you're concerned about it I'll edit the answer and include a .NET 3.5 and VS 2008 solution as well.

          – Visual Vincent
          Jan 2 at 17:09















          Haha, no I am not concerned; great solution BTW.

          – Çöđěxěŕ
          Jan 2 at 17:15







          Haha, no I am not concerned; great solution BTW.

          – Çöđěxěŕ
          Jan 2 at 17:15






          1




          1





          @Çöđěxěŕ : Too late, added it anyway ;). Also, thanks!

          – Visual Vincent
          Jan 2 at 17:22





          @Çöđěxěŕ : Too late, added it anyway ;). Also, thanks!

          – Visual Vincent
          Jan 2 at 17:22




          1




          1





          @Çöđěxěŕ Where is the upvote for the "great solution"?

          – Mary
          Jan 2 at 18:17





          @Çöđěxěŕ Where is the upvote for the "great solution"?

          – Mary
          Jan 2 at 18:17




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54007710%2fcontinue-for-loop-if-a-file-is-created-in-vb-net%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          The term 'EXEC' is not recognized as the name of a cmdlet Powershell

          NPM command prompt closes immediately [closed]

          Error binding properties and functions in emscripten