467,145 Members | 971 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,145 developers. It's quick & easy.

VB App (2003) Problems with Processes (I think)


We have a program that calls two other processes one of which creates a Python script which is ran by a third party software (Abaqus).

This script creates a input file which is used in the code later.

Toward the end of the code I want to delete that input file, but everytime I try, I get a Error message saying that I can't as its being used by a Process. Unfortunately, because of the way this third party program is, I can't debug this in the normal way, and have to build the code each time, and run it on the client's computer by remote access. So, my error messages are archaic at best.

Here are some code snipets which may offer some insight into the problem:
This first bit is the process call that creates the input file called "<something>_core_full.inp". I recently added the kill bit and it doesn't help
Expand|Select|Wrap|Line Numbers
  1. Private Sub RunAbaqus_INP()
  2.         Dim RunAbaqusINPProc As Process
  3.         RunAbaqusINPProc = New Process
  4.         RunAbaqusINPProc.StartInfo.WorkingDirectory = strWorkingDir
  5.         RunAbaqusINPProc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
  6.         If optVer66.Checked = True Then
  7.             RunAbaqusINPProc.StartInfo.FileName = "abq66ef1"
  8.         Else
  9.             RunAbaqusINPProc.StartInfo.FileName = "abq663"
  10.         End If
  11.         RunAbaqusINPProc.StartInfo.Arguments = " cae noGUI=create_inp_script.py"
  12.         RunAbaqusINPProc.Start()
  13.         If Not RunAbaqusINPProc Is Nothing Then
  14.             Do Until RunAbaqusINPProc.HasExited
  15.                 JobThread2.Sleep(1000)
  16.             Loop
  17.             RunAbaqusINPProc.Dispose()
  18.             RunAbaqusINPProc.Kill()
  19.         End If
  20.     End Sub
Here is the code that calls the two threads and attempts to wait for them to finish before continuing with the code.
Expand|Select|Wrap|Line Numbers
  1. ...
  2. 'create the main python script
  3.         JobThread = New Thread(AddressOf Me.RunAbaqus)
  4.         JobThread.Start()
  5.         JobThread.Join()
  7.         'create the python INP converter script.
  8.         JobThread2 = New Thread(AddressOf Me.RunAbaqus_INP)
  9.         JobThread2.Start()
  10.         JobThread2.Join()
  12.         While JobThread2.IsAlive Or JobThread.IsAlive
  13.             Threading.Thread.Sleep(1000)
  14.         End While
  15. ...
The ONLY other code in the app that accesses this input file (*_core_full.inp) is in a subroutine that parses it using arrays and toward the end of the sub, it attempts to delete it with:
Expand|Select|Wrap|Line Numbers
  1. Dim objReader As StreamReader = New StreamReader(InputFile)
  2. ...
  3. objReader.Close()
  4.         'move the deletion of the core_file here to see if it works here
  5.         If File.Exists(Path.Combine(WorkingDir, ODBName & "_core_full.inp")) Then
  6.             File.Delete(Path.Combine(WorkingDir, ODBName & "_core_full.inp"))
  7.         End If
This is the code where the program crashes everytime.

Can anyone offer any thoughts, to how I can make sure there are no processes still "using" or "attached to this" file when I delete it?

Sep 7 '07 #1
  • viewed: 1102
7 Replies
Expert 4TB
So you call a proccess which happens to be a python script.
That script creates the file.
You wait for the process to finish
You then readin the file (and close it with the StreamReader.Close() )
Then try to delete it?

That all seems fine, unles for some reason the python script does not close the file properly and something stays open there.

You could look up ways to check on what process has a file open?
The ProcessExplorer (endorsed by microsofts dev team?) gives a lot of good information like this and might be helpful?
Sep 7 '07 #2
Unfortunately, I can't get into the ProcessExplorer (is that the same as Debug Processes, in 2003?) on the Client's machine. Heck, I can't technically test it myself, I give it to an engineer to run the tests.

Are you saying the code provided looks like it "should" work?

Sep 7 '07 #3
Expert 4TB
theoretically yes, I didn't notice anything wrong, rather confusing.
Sep 7 '07 #4
half the time, my posts don't show up...is there a vetting process which they are getting lost in?

I had added a conceptual question, could sub routines that my code calls be called a "process", or are "processes" ONLY Items I've created actual processes?

The engineer I'm working with claims that the vague error message we're getting "<filename> can't be deleted as its being accessed by another process", is referring to one of my subroutines within the program, I content that its the python script that is being ran by Abaqus which isn't releasing the file.

I would share the python script, but its just a list of Abaqus commands, so I don't think it would be very helpful...unless one of you know abaqus, PM me, and I'll PM that code to you for your review.

Sep 7 '07 #5
Expert 4TB
Sort of correct, that error message is a general "file is in use" error, which INCLUDES anything in your program that has opened a handle to it (filestream, streamreader, streamwriter, whatever...) that has not released control of it yet.
Sep 7 '07 #6
First off thanks for your help...

There are only two things that 'use' that file. The Abaqus process that creates it.

And my code that uses it (as the input file). Here is where I release it at the end of my subroutine. Did I forget anything?

Expand|Select|Wrap|Line Numbers
  1.  objReader.Close() 'objReader is a Streamreader object.
One thing occurred to me when I was typing this...I start reading the file over about 4 times in my code (does that create 3 seperate instances of the objReader, or do they get "used-over" each time I instantiate a new one, as I use the same name "objReader" every time? I'll try adding an "objReader.close() at the end of each usage.

Sep 10 '07 #7
Expert 4TB
if you say objreader = new (whatever)
use objreader
and then say objreader=new (whatever) AGAIN without a close, then no, I don't think the previous stream is closed. (it will close when the program exits, and maybe when a garbage collection happens, but will probably stay open)
Sep 10 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Lars Siden | last post: by
reply views Thread by Richard Grene | last post: by
1 post views Thread by ib | last post: by
3 posts views Thread by Julia | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.