Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 269
  • Last Modified:

"End Task" a frozen application

I run a vb program that I created and it is vital that it runs smoothly. My program takes control of another program which downloads information from another location. It is done every morning before anybody is in the office.

Everything works fine except that about once a week the program that VB is controlling gets timed out and is frozen. The only way to restart it is to "End Task".

The way I see it there are 2 options:(I am open to any options though)

1.Have multiple versions of the program running.
This would work except that I do not know how to refer to more than one instance of this program. Does Windows provide a way for Visual Basic to do this. If I run the VB code, it tries to perform the operations on the first version opened. If there was a way to loop through all the open applications and find the next instance, that would be great!

2. Use a command similar to "End Task" and terminate the program. The whole process should not take more than 45 minutes.The program that I control has no error handling (which is just great). But I could run a version of the VB program every hour starting at 3 AM until it runs successfully.I would then be able to open a new version of the program and continue the operations.

Thanks to anybody who took the time to read this!

1 Solution
Could we see the code for "controlling" the other program?
what about if you write a another program, which calls this VB program everyday and closes it after a certain period.  This way, you don't have to worry about running multiple instances of the VB program, run the startup program with hardcoded timining options.
Determine if an Application has Stopped Responding and terminate if it has:

vbaRookieAuthor Commented:
Here is the code for the program:

Private Sub QueriesToRun()

Dim acc As Access.Application
Dim rst As DAO.Recordset
Dim objApp As Object
Dim DataMdl As Object
Dim Dwindow As Object
Dim PromptDate As Object
Dim DWbutton As Object
Dim SatDate As Date
Dim FriDate As Date
Dim fTextFile As TextStream
Dim fFile As File
Dim fSysObject As FileSystemObject
Dim rstPrompts As DAO.Recordset
Dim rstQry As DAO.Recordset

On Error GoTo ErrorHandler:

Set objApp = GetObject(, "Query.UpDate.Application")
'take control of the open application
'this is the part that I need help on

Set DataMdl = objApp.DataModel
'sets the open data model to the object
objApp.Visible = True

Set acc = New Access.Application
acc.OpenCurrentDatabase "H:\data\Scheduler\Scheduler.mdb"
'loop through an Access table of queries to run,along with
'the properties needed for it to run
''''''''''''''''''''''''''''''''''start loop
Set rstPrompts = acc.CurrentDb.TableDefs("tblDWPrompts").OpenRecordset
Do Until rstPrompts.EOF = True
Set PromptDate = DataMdl.Prompts(rstPrompts.Fields("strPRMTPromptName").Value)
Set rstQry = acc.CurrentDb.QueryDefs(rstPrompts.Fields("strPRMTQueryToFindPrompt").Value).OpenRecordset
PromptDate.Confirm = False
PromptDate.AddValue (rstQry.Fields(rstPrompts.Fields("strPRMTQueryFieldName").Value))
Me.lstStatus.AddItem PromptDate.Name & "'s value is " & rstQry.Fields(rstPrompts.Fields("strPRMTQueryFieldName").Value)

'''''''''''''''''''''''''''''''''''start loop
Set rst = acc.CurrentDb.TableDefs("tblScheduleTasks").OpenRecordset

Do Until rst.EOF = True
Set fSysObject = New FileSystemObject
Set fFile = fSysObject.GetFile("H:\Data\Reports\QRD\" & Trim(rst.Fields("strDWQrdName")))
'set to look at each qrd

If Format(fFile.DateLastModified, "Short Date") <> Format(Date, "Short Date") Then
'logic to see if it has been run

Set Dwindow = DataMdl.Windows(Trim(rst.Fields("strDWWindowOnDW")))

'the following is the code to run the Query Program


Set DWbutton = Dwindow.Buttons(Trim(rst.Fields("strDWButtonOnDW")))
lstStatus.AddItem DWbutton.Name & " OK at " & Time
FileCopyToNetwork Trim(rst.Fields("strDWQrdName"))

End If
rst.MoveNext 'move to the next record in the table

Exit Sub

MsgBox "objApp ERROR " & Err.Number & Err.Description
End Sub
I hope that was not too much code, only the first part with the GetObject is very important to this question.
I hope this helps

The program opens from a command line like this
"C:\Program Files\Query\update.exe" "R:\Query\OnDemand\OnDemandIBM.gqu"
Both must be run in order for the program to function properly. I am able to use the shell function to open it, but I still can't differentiate which Query Application to take control of. When the first one "freezes" I am stuck.
vbaRookieAuthor Commented:
Thank you very much, I was able to take what I needed out of the source code. Thanks to everybody who helped!

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now