aspnet_wp will not release file handle

Discussion in 'ASP .Net' started by fernandez.dan@gmail.com, Feb 11, 2005.

  1. Guest

    I have a umangaged dll ( I have the source code) which I use in my web
    app using pinvoke. The dll creates a file, writes to it, and then
    closes it. It works the first time through but the second time through
    it can't open file so my dll fails and returns an error number.

    I then try to delete the file manually but it says that I can not
    delete it because it is use by other program or user. I used process
    explorer utility from sysinternals to find out who had the file handle.
    It seems that the aspnet_wp has the file handle.

    It's weird if I wait for a long period of time, I can finally manually
    delete the file. I'm not sure if it takes a period of time for the
    aspnet_wp process to release resources.

    Just an high overview of the file call sequence in my unmanaged dll
    int pMode = 0x20;
    hFile = CreateFile(filename,GENERIC_WRITE,0, NULL, CREATE_ALWAYS,
    pMode, NULL);
    WriteFile(hFile,cmdstring,strlen(cmdstring), &bytes,NULL);
    CloseHandle(hFile);

    I appreciate any advice.
     
    , Feb 11, 2005
    #1
    1. Advertising

  2. Scott Allen Guest

    Does your .NET code use the file at all? Or just the unmanaged dll? It
    appears to be closed correctly, assuming there are no branches or
    exceptions that would cause the execution path to miss the CloseHandle
    API.

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    On 11 Feb 2005 12:31:09 -0800, wrote:

    >I have a umangaged dll ( I have the source code) which I use in my web
    >app using pinvoke. The dll creates a file, writes to it, and then
    >closes it. It works the first time through but the second time through
    >it can't open file so my dll fails and returns an error number.
    >
    >I then try to delete the file manually but it says that I can not
    >delete it because it is use by other program or user. I used process
    >explorer utility from sysinternals to find out who had the file handle.
    >It seems that the aspnet_wp has the file handle.
    >
    >It's weird if I wait for a long period of time, I can finally manually
    >delete the file. I'm not sure if it takes a period of time for the
    >aspnet_wp process to release resources.
    >
    >Just an high overview of the file call sequence in my unmanaged dll
    >int pMode = 0x20;
    >hFile = CreateFile(filename,GENERIC_WRITE,0, NULL, CREATE_ALWAYS,
    >pMode, NULL);
    >WriteFile(hFile,cmdstring,strlen(cmdstring), &bytes,NULL);
    >CloseHandle(hFile);
    >
    >I appreciate any advice.
     
    Scott Allen, Feb 11, 2005
    #2
    1. Advertising

  3. Guest

    Yeah,

    The filename is based on the user information provided in a web form so
    the filename can change from user to user. So I just use the
    Directory.GetFiles call to get the files in a directory and search for
    my file by a keyword from the web form. When I find the file I'm
    looking for, I get the full path name so I can set up a URL for the
    user to download it if they choose.

    But there is a chance that information provided by the user can lead to
    the same filename, so before calling the unmanaged dll I try to delete
    the file with the same keyword. When the file gets locked this
    opeartion throws an exception because it can't delete the file.

    I know it's weird but even if I have the source for the dll, I
    constraint what I can do to it.

    Here is the sequence
    User enters info in web form and submits
    I check if any other file with same keyword if so delete
    Call unmanaged dll with user info
    Lookup file with keyword and set up URL path

    Thanks
     
    , Feb 11, 2005
    #3
  4. Scott Allen Guest

    Interesting, because it really does sound like it should work. I was
    thinking perhaps the code opened the file to send results back to the
    user but didn't Close or Dispose the File object and left the file
    open.

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    On 11 Feb 2005 13:32:34 -0800, wrote:

    >Yeah,
    >
    >The filename is based on the user information provided in a web form so
    >the filename can change from user to user. So I just use the
    >Directory.GetFiles call to get the files in a directory and search for
    >my file by a keyword from the web form. When I find the file I'm
    >looking for, I get the full path name so I can set up a URL for the
    >user to download it if they choose.
    >
    >But there is a chance that information provided by the user can lead to
    >the same filename, so before calling the unmanaged dll I try to delete
    >the file with the same keyword. When the file gets locked this
    >opeartion throws an exception because it can't delete the file.
    >
    >I know it's weird but even if I have the source for the dll, I
    >constraint what I can do to it.
    >
    >Here is the sequence
    >User enters info in web form and submits
    >I check if any other file with same keyword if so delete
    >Call unmanaged dll with user info
    >Lookup file with keyword and set up URL path
    >
    >Thanks
     
    Scott Allen, Feb 11, 2005
    #4
  5. Guest

    Yeah it is weird,

    Plus if I wait long enough I can then delete the file. It's like it's
    taking aspnet_wp process awhile to let go of the handle. I am curious
    if there is a way to force aspnet_wp to let go of the file handle or if
    I can force a delete on a file.

    I am open for any options. Thanks

    Danny
     
    , Feb 11, 2005
    #5
  6. Check to see if the Indexing Service is on.

    If it is, turn the service off, and test again.




    Juan T. Llibre
    ASP.NET MVP
    http://asp.net.do/foros/
    Foros de ASP.NET en EspaƱol
    =====================

    <> wrote in message
    news:...
    > Yeah it is weird,
    >
    > Plus if I wait long enough I can then delete the file. It's like it's
    > taking aspnet_wp process awhile to let go of the handle. I am curious
    > if there is a way to force aspnet_wp to let go of the file handle or if
    > I can force a delete on a file.
    >
    > I am open for any options. Thanks
    >
    > Danny
    >
     
    Juan T. Llibre, Feb 11, 2005
    #6
  7. Guest

    Thanks Guys,

    I was using someone else code to log my entry in a database. My friend
    forgot to close the file. He read the file and log the file in a
    database. I think he owe's me a red bull, I spent hours on my code
    trying to figure out what I did wrong.

    Thanks for all the help.

    Danny
     
    , Feb 11, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dietrich
    Replies:
    1
    Views:
    649
    Joe Smith
    Jul 22, 2004
  2. Leon
    Replies:
    2
    Views:
    536
  3. =?ISO-8859-1?Q?KLEIN_St=E9phane?=
    Replies:
    3
    Views:
    454
    hanumizzle
    Oct 6, 2006
  4. Chris McFarling
    Replies:
    0
    Views:
    367
    Chris McFarling
    Sep 25, 2008
  5. Bo Schwarzstein

    how to release file handle in xercesc

    Bo Schwarzstein, Dec 1, 2008, in forum: XML
    Replies:
    1
    Views:
    443
    Bo Schwarzstein
    Dec 4, 2008
Loading...

Share This Page