Starting a process in a thread

I am curious about being able to launch a process such as Process.start(c:\SomeDoc.doc) as a thread.  I don't really understand threads very well so if this does not make sense let me know.  If it does, can I see a code snipetf for using using a thread for a process.

Thanks,
Fred H


Answer this question

Starting a process in a thread

  • QuanT - MSFT

    Hi Fred,

    You can launch a process on threads. The following code snippet shows how you can do the same:


    Public Class ProcessLauncher
      Dim strProcessPath As String
     
     Public
    Property ProcessPath() As String
      Get
        Return (strProcessPath)
      End Get

       Set(ByVal value As String)
        strProcessPath = value
       End Set
     End Property

     Public Sub LaunchProcess()
        Process.Start(strProcessPath)
     End Sub
    End
    Class


     




    Sub Main()
       Dim objProcessLauncher1 As New ProcessLauncher() 
       objProcessLauncher1.ProcessPath =
    "C:\Windows\Notepad.exe"
      Dim objThreadStart1 As New ThreadStart(AddressOf objProcessLauncher1.LaunchProcess)

     Dim objThread1 As New Thread(objThreadStart1)
     Dim objProcessLauncher2 As New ProcessLauncher()
     objProcessLauncher2.ProcessPath =
    "c:\WINDOWS\system32\calc.exe"

     

      Dim objThreadStart2 As New ThreadStart(AddressOf objProcessLauncher2.LaunchProcess)

       Dim objThread2 As New Thread(objThreadStart2)
     
       objThread1.Start()
       objThread2.Start()
    End Sub


     


    Regards,
    Vikram



  • Starting a process in a thread