|
-
Sep 16th, 2012, 11:40 PM
#1
Thread Starter
Hyperactive Member
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.
-
Sep 17th, 2012, 12:34 AM
#2
Re: How to execute a process for running executable files in parallel?
 Originally Posted by adshocker
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.
-
Sep 17th, 2012, 12:54 AM
#3
Thread Starter
Hyperactive Member
Re: How to execute a process for running executable files in parallel?
Hi jmcilhinney,
I'm using Oracle Database Express Edition 11g.
-
Sep 17th, 2012, 01:06 AM
#4
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.
-
Sep 19th, 2012, 11:46 PM
#5
Thread Starter
Hyperactive Member
Re: How to execute a process for running executable files in parallel?
 Originally Posted by jmcilhinney
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.
-
Sep 19th, 2012, 11:50 PM
#6
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.
-
Sep 20th, 2012, 12:09 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|