Results 1 to 7 of 7

Thread: How to execute a process for running executable files in parallel?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    How to execute a process for running executable files in parallel?

    Hi,

    I'm currently working on an application that will always run and check/fetch a set of records from my database. The program will do this probably for every 10 seconds (Will use a timer for this unless there's a better way). The table consists of data regarding executable files and their corresponding location in the server.

    Table structure.
    Code:
    Filename
    Status 'Could be Waiting, In Process or Finished'
    Now when my program loops over these Waiting records, I need to run this executable file, set the Status column to 'In Process' then wait for them to finish and set the Status column to 'Finished'. Currently my approach is something like...
    Code:
    Public Sub SetInProgress(ByVal Filename As String)
      'Do updates here.
    End Sub
    
    Public Sub SetFinished(ByVal Filename As String)
      'Do updates here.
    End Sub
    
    Public Sub Run(ByVal Filename as String)
      Dim p As New Process
      p = Process.Start(Filename)
    End Sub
    
    Public Sub Main()
      For Each row As DataRow In DataTable.Rows
        Run(row("Filename"))
        SetInProgress(row("Filename"))
      Next
    End Sub
    Setting the Status to 'Finished' is the problem I'm having now as I don't know how to check whether the Process has ended or not. Then I thought of adding the Procedure SetFinished after the line p = Process.Start like shown below.

    Code:
    Public Sub Run(ByVal Filename as String)
      Dim p As New Process
      SetInProgress()
      p = Process.Start(Filename)
      SetFinished()
    End Sub
    But the above code will prevent me from running multiple processes at the same time. Also I need to have the ability to Stop a process from running.

    How can I do this?

    Thanks.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to execute a process for running executable files in parallel?

    Quote Originally Posted by adshocker View Post
    Hi,

    I'm currently working on an application that will always run and check/fetch a set of records from my database. The program will do this probably for every 10 seconds (Will use a timer for this unless there's a better way).
    What database are you using? If it's SQL Server then there may well be a better way.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Re: How to execute a process for running executable files in parallel?

    Hi jmcilhinney,

    I'm using Oracle Database Express Edition 11g.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to execute a process for running executable files in parallel?

    Forget my previous post. I should have read your first post more carefully.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Re: How to execute a process for running executable files in parallel?

    Quote Originally Posted by jmcilhinney View Post
    Forget my previous post. I should have read your first post more carefully.
    No worries.

    Anyways, I managed to get this to work by using System.Threading.Thread. My only concern now whether to use Form on System Tray or Windows Service since this should be running in the background. I haven't tried Windows Service that connects to a Database. Will it support Datasets,DataAdapters/TableAdapters/DataTables etc.? Also, which is recommended in my scenario?

    Thanks.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to execute a process for running executable files in parallel?

    A Windows service is just an application like any other, so the code you write in it will be the same as any other. The only difference with a Windows service is how it's started up and the fact that there is no interactive user. If you want the application to be running all the time then you would probably lean towards a Windows service, unless a physical user needs to interact with it. If the app only needs to run some of the time then a Windows Forms app with a NotifyIcon would be the best bet if the user needs to interact with it. If they don't then a Console app, possibly started using Windows Scheduled Tasks might be the best option. If you do decide to go with WinForms and you want to start without a main form then follow the CodeBank link in my signature and check out my Formless Tray App thread.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: How to execute a process for running executable files in parallel?

    Services support most things will support all of that ... however I made a program once that detects when windows powers the screen on and off and turns my tv on and off accordingly with an iboot power controler, where it wouldn't run as a service as to pickup the WM_POWERBROADCAST you need to register the notification with the window handle and capture this through WndProc ....

    Windows forms will not run under a service, so i used task scheduler instead.

    Also by the sounds of it you would do well to use a thread timer in a service...

    Kris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width