Results 1 to 2 of 2

Thread: Clearing File Streams on Error

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2004
    Posts
    14

    Clearing File Streams on Error

    Hello,

    I have an application which opens various files for reading and writing. The problem I'm having is, if the application errors for whatever reason, the file streams stay open, so next time I run the application I get a "Cannot open file as it is being used by another process.".

    The only way to get around this is by ending the task aspnet_wp.exe in task manager. I can't do this in a live environment.

    Does anyone know of a solution to this. I was thinking of adding some code in the Application_Error event to check which filestreams are open, and ending them.

    Cheers!

  2. #2
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251

    Re: Clearing File Streams on Error

    Put your streams in a try catch block.

    VB Code:
    1. Try
    2.    'some code
    3. Catch ex as Exception
    4.   Throw
    5. Finally
    6.   stream.close
    7. End Try

    Finally blocks will run no matter what, so if your code errors inside the Try block, the Catch block will throw the error and the Finally block will execute
    ~Ryan





    Have I helped you? Please Rate my posts.

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