?
Solved

"End Task" a frozen application

Posted on 2003-03-12
5
Medium Priority
?
266 Views
Last Modified: 2010-05-01
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!

0
Comment
Question by:vbaRookie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 5

Expert Comment

by:JMoon5FTM
ID: 8122949
Could we see the code for "controlling" the other program?
0
 
LVL 11

Expert Comment

by:supunr
ID: 8123325
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.
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 740 total points
ID: 8123948
Determine if an Application has Stopped Responding and terminate if it has:

http://www.thescarms.com/VBasic/AppResponse.asp
0
 
LVL 1

Author Comment

by:vbaRookie
ID: 8130899
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
rstPrompts.MoveFirst
Do Until rstPrompts.EOF = True
Set PromptDate = DataMdl.Prompts(rstPrompts.Fields("strPRMTPromptName").Value)
Set rstQry = acc.CurrentDb.QueryDefs(rstPrompts.Fields("strPRMTQueryToFindPrompt").Value).OpenRecordset
PromptDate.ClearValues
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)
rstPrompts.MoveNext
Loop

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

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

objApp.Activate
DataMdl.Activate
Dwindow.Activate

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

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

Loop
''''''''''''''''''''''''''''''''''''
Exit Sub
ErrorHandler:

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.
0
 
LVL 1

Author Comment

by:vbaRookie
ID: 8140914
Thank you very much, I was able to take what I needed out of the source code. Thanks to everybody who helped!
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 5 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question