473,837 Members | 1,657 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Counting file handles on a file

Hello all,

I am waiting for receipt of files in a directory. I use the
FileSystemWatch er to detect when files arrive in said folder. I need
to read the data from these files ASAP but the files are created and
detected before writing completes and so I cannot read them until the
file handle used in their creation has been released.

This would be easy to get around with file renaming or other file
locking mechanisms which I could use except that I have no control
over the file "drops" because they are from a 3rd party and not about
to change. I simply see the files arrive.

So, in brief, how can I determine the number of file handles on a file
so that when one arrives I can wait until it is released?

Thanks,
Conrad
Nov 16 '05 #1
18 20199

"Conrad F" <co*********@ho tmail.com> wrote in message
news:6a******** *************** ***@posting.goo gle.com...
Hello all,

I am waiting for receipt of files in a directory. I use the
FileSystemWatch er to detect when files arrive in said folder. I need
to read the data from these files ASAP but the files are created and
detected before writing completes and so I cannot read them until the
file handle used in their creation has been released.

This would be easy to get around with file renaming or other file
locking mechanisms which I could use except that I have no control
over the file "drops" because they are from a 3rd party and not about
to change. I simply see the files arrive.

So, in brief, how can I determine the number of file handles on a file
so that when one arrives I can wait until it is released?

Thanks,
Conrad


You can't touch the file as long as it isn't written and closed completely,
so you can't get at the file handles too, the only thing you can do is wait
in a loop that tries to open the file.

Willy.

Nov 16 '05 #2
Not sure if this will work for your issue or even if it is the same in .net.
We have a process that does something similar to what you want, what we
noticed is that the file size remained 0 until the file had been completely
written. You may check to see if getting a list of the files shows this to
be true for you as well.

In our scenario the files are always less then 1k, always written by IIS and
we used the FindFirst/FindNext in win32 API to check for files.

--
Thanks
Wayne Sepega
Jacksonville, Fl
"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

"Conrad F" <co*********@ho tmail.com> wrote in message
news:6a******** *************** ***@posting.goo gle.com...
Hello all,

I am waiting for receipt of files in a directory. I use the
FileSystemWatch er to detect when files arrive in said folder. I need
to read the data from these files ASAP but the files are created and
detected before writing completes and so I cannot read them until the
file handle used in their creation has been released.

This would be easy to get around with file renaming or other file
locking mechanisms which I could use except that I have no control
over the file "drops" because they are from a 3rd party and not about
to change. I simply see the files arrive.

So, in brief, how can I determine the number of file handles on a file
so that when one arrives I can wait until it is released?

Thanks,
Conrad

Nov 16 '05 #3
Hi,
I'm quite interested in your topic and do a little research,
I just found http://www.sysinternals.com/ntw2k/source/filemon.shtml
..That is a file moniotr application,at that page you can find
"On Windows NT the heart of FileMon is a file system driver that creates and
attaches filter device objects to target file system device objects so that
FileMon will see all IRPs and FastIO requests directed at drives. When
FileMon sees an open, create or close call, it updates an internal hash
table that serves as the mapping between internal file handles and file path
names. "

So I go on googling and find that maybe you need to do some kind of
driver development,whi ch is "File System Filter Drivers".I think by
those way you can certainly get all the I/O operation you want to know,
which is out of my capability.

If anyone got a good idea,please let me know.
Good luck.
Daiyue

"Willy Denoyette [MVP]" <wi************ *@pandora.be> 写入消息新闻:ex *************** @TK2MSFTNGP15.p hx.gbl...

"Conrad F" <co*********@ho tmail.com> wrote in message
news:6a******** *************** ***@posting.goo gle.com...
Hello all,

I am waiting for receipt of files in a directory. I use the
FileSystemWatch er to detect when files arrive in said folder. I need
to read the data from these files ASAP but the files are created and
detected before writing completes and so I cannot read them until the
file handle used in their creation has been released.

This would be easy to get around with file renaming or other file
locking mechanisms which I could use except that I have no control
over the file "drops" because they are from a 3rd party and not about
to change. I simply see the files arrive.

So, in brief, how can I determine the number of file handles on a file
so that when one arrives I can wait until it is released?

Thanks,
Conrad


You can't touch the file as long as it isn't written and closed
completely, so you can't get at the file handles too, the only thing you
can do is wait in a loop that tries to open the file.

Willy.

Nov 16 '05 #4

"Wayne" <Me******@commu nity.nospam> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Not sure if this will work for your issue or even if it is the same in
.net.
We have a process that does something similar to what you want, what we
noticed is that the file size remained 0 until the file had been
completely
written. You may check to see if getting a list of the files shows this to
be true for you as well.

In our scenario the files are always less then 1k, always written by IIS
and
we used the FindFirst/FindNext in win32 API to check for files.


And what would be the advantage of this over simply trying to open the file
in a loop?

Willy.
Nov 16 '05 #5

"daiyue" <my******@gmail .com> wrote in message
news:eL******** ******@TK2MSFTN GP09.phx.gbl...
Hi,
I'm quite interested in your topic and do a little research,
I just found http://www.sysinternals.com/ntw2k/source/filemon.shtml
.That is a file moniotr application,at that page you can find
"On Windows NT the heart of FileMon is a file system driver that creates
and attaches filter device objects to target file system device objects so
that FileMon will see all IRPs and FastIO requests directed at drives.
When FileMon sees an open, create or close call, it updates an internal
hash table that serves as the mapping between internal file handles and
file path names. "

So I go on googling and find that maybe you need to do some kind of
driver development,whi ch is "File System Filter Drivers".I think by
those way you can certainly get all the I/O operation you want to know,
which is out of my capability.

If anyone got a good idea,please let me know.
Good luck.
Daiyue


That won't help you either as part of this stuff is based on "non
documented" native OS calls.
Most sysinternals tools are great as a test/debug tools but I won't rely on
it for production code.

illy.
Nov 16 '05 #6
Never said it would have an advantage over opening the file in a loop, just
a different approach.

--
Thanks
Wayne Sepega
Jacksonville, Fl
"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message
news:uY******** ******@TK2MSFTN GP14.phx.gbl...

"Wayne" <Me******@commu nity.nospam> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Not sure if this will work for your issue or even if it is the same in
.net.
We have a process that does something similar to what you want, what we
noticed is that the file size remained 0 until the file had been
completely
written. You may check to see if getting a list of the files shows this to be true for you as well.

In our scenario the files are always less then 1k, always written by IIS
and
we used the FindFirst/FindNext in win32 API to check for files.

And what would be the advantage of this over simply trying to open the

file in a loop?

Willy.

Nov 16 '05 #7
Hi,

1) Hopefully, doing it some other way will allow asynchronous
monitoring and not put processor usage at 100% while it does nothing
but check a file thousands of times
2) I don't want to lock up the front-end GUI
3) If I tie the program up in a loop, it won't receive event
notifications of other file arrivals if it is stuck in a loop!

Conrad

Nov 16 '05 #8
I am at home now, but if this is true I could probably detect the
change of file size with the FileSystemWatch er class still, which is
ideal.

I will check it out tomorrow!

Nov 16 '05 #9
I am not sure that's true. I have (a few years ago) managed to read
large files while they were still being written by another process and
have consequently ended up reading past the end of a file before an EOF
marker is set - not with nice results either as it was in VB at the
time, threw a GPF and my IDE just disappeared!

If .NET does have to open the file and it is exclusively locked to
another process, then there will be a big delay in an order of seconds
the first time .NET throws an exception - it sounds a small amount of
time but it is large in terms of the amount of files being processed
and the speed requirments. The files are always 5k or less and are
purely XML.

I am fairly sure that a few years ago (when I still used the WIN32API
alot) that there was a call to enumerate the file handles on a
file!?!?!? How else can you tell if a file is in use by another process
without excessive process monitoring?

Nov 16 '05 #10

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

Similar topics

12
2605
by: Woodster | last post by:
I currently have some code for an application that is running on Win32. I have tried to keep anything not directly gui related as separate as possible for portability reasons, including file access. Now has come the time to try and implement the program on a Windows CE platform. Problem is, that the MFC CArchive class uses an integer file pointer and calls to open, close etc and my file handling class is doing everything with FILE *, such...
0
3404
by: j jpenney | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** Hello, I'm working on a problem we've been having with an OAS deployed application. We have a W2K3 machine running OAS 10g, with an application that hits a database on another machine. The server runs fine under light loads (we haven't run under heavy load yet), but on the weekends we're getting a hard crash of the server. When we look at the memory dump, we're seeing the...
3
1929
by: gmtonyhoyt | last post by:
Okay, this one's a tough one for me to explain so this might take a few e-mails to get the idea across. Here's what I got though. I have this application running on a Sun/Solaris machine, written in C, using the Sun Forte Developer 7 C 5.4 Compiler released a few years ago. Not exactly old but, you get the picture. Now, most if not all the file handles on this machine are most likely being used up by a secondary process and/or...
4
5306
by: Tony Liu | last post by:
Hi, how can I create multiple new file handles of a file without having to share to file to the other processes? I have a file that will be accessed by multiple threads in my application, each time a thread try to do something with the file, the thread will create a new file handle. However, if I specify FileShare.ReadWrite, other process can also open that file. I tried FileShare.Inheritable but it doesn't work. The reason I needs to...
1
1472
by: Matt Gertz | last post by:
Phil, Thanks for the notification on this. I'm going to do some investigation on this today & try debugging through the problem, and I'll get back to you either this afternoon or tomorrow morning. (My response will be posted in languages\vb, since this is likely to be a VB issue -- I'll drop a copy of this post over there.) Thanks, --Matt Gertz--* VB Compiler Dev Lead
2
2957
by: SharpCoderMP | last post by:
hi, in my app i monitor the filesystem for changes with FileSystemWatchers. When the change is detected the app performs some actions using Shell32 to obtain information from the filesystem. now the problem is that apparently the CLR not always closes the file handles immediately. this is rather annoying to the user because he's unable to change (write, delete, rename) these locked files or directories. the strangest thing is that some...
14
2095
by: Dan | last post by:
Is this discouraged?: for line in open(filename): <do something with line> That is, should I do this instead?: fileptr = open(filename) for line in fileptr: <do something with line>
1
4668
by: =?Utf-8?B?RGVtZXRyaQ==?= | last post by:
The short question I have here is how would one enumerate file handles for a given process in C#? I know p/invoke is needed. Sysinternals uses NtQuerySystemInformation and NtQueryObject. However, my knowledge of how to uses these are pretty limited and to save myself some time of ramping up on them I was wondering if someone already knew how to do this in C#? Or can point me to some sample code on doing this would be great. I have...
2
2627
by: charlesbritto | last post by:
A C++ program for counting individual string in a text file using file handling functions., for ex: if the text file contains, am a boy,am studying +2,am from chennai Now the result shoud be as 3 bcaz ("am" presenting 3 times)
0
9828
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we抣l explore What is ONU, What Is Router, ONU & Router抯 main usage, and What is the difference between ONU and Router. Let抯 take a closer look ! Part I. Meaning of...
0
10560
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10263
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9390
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梡lanning, coding, testing, and deployment梬ithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6988
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5840
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4469
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4034
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3120
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.