473,508 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

aspnet_wp will not release file handle

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.

Nov 19 '05 #1
6 2955
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, fe***********@gmail.com 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.


Nov 19 '05 #2
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

Nov 19 '05 #3
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, fe***********@gmail.com 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


Nov 19 '05 #4
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

Nov 19 '05 #5
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
=====================

<fe***********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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

Nov 19 '05 #6
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

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5348
by: | last post by:
This question references to KB articles: http://support.microsoft.com/default.aspx?scid=kb;EN-US;315158 http://support.microsoft.com/default.aspx?scid=kb;EN-US;317012 I'm running Advanced Server...
7
7154
by: Clement | last post by:
hi, i have an asp.net site and is using SQL Server 2k. i realize the aspnet_wp.exe memory usage keep growing and i will receive an error for the pages that call the sql connection. others page...
2
1648
by: Akoni | last post by:
Hello, I have written a ASP.NET (C#) front-end that connects to an unmanaged win32 c++ dll. A few problems occur: -I am unable to use the IO stream (write to an event log) from the dll....
6
1334
by: Trapulo | last post by:
On my server (dual XEON 1GB ram) aspnet_wp is using a lot of ram: 500MB ram, 585MB virtual. The server reports only 7.5MB ram free and 30MB system cache. Is this normal? Why garbage collector...
8
1149
by: Rusty Shackleford | last post by:
Is it normal behavior for the aspnet_wp.exe process to exit immediately after starting? This is happening to me without any errors in the application event log. No matter what ASP.Net application...
0
1332
by: bpssolutions | last post by:
hi- i'm going mad over here. any help would be greatly appreciated. aspnet_wp.exe hangs whenever i browse to the virtual directory in which i am developing, sucking up all CPU time. any...
3
3968
by: Ramesh Dodamani | last post by:
Environment: XP Pro, VS.Net 2003, .Net 1.1.4322 with SP1 & KB Hotfix 886903 P4 2.2GHz, 1 GB RAM My system was working fine till a few weeks back when I started seeing the following errors. ...
3
1972
by: MP | last post by:
Hi, I have a library in which I use the COM+ services dynamically for creating a Folder in the virtual directory of the Web Application on the Web Server. As ASPNET account does not have...
0
824
by: Chris McFarling | last post by:
I have a basic aspx page for the user to select the month & year. They then click a button to generate a report. The following sequence happens: - Temp directory is created (if it exists already,...
0
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
435
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.