473,382 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

File Sharing and multiple file handles

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 create a new file handle each time is because those
different threads will be working on a different area of the file and I just
can't share a single master file handle.

Thanks in advance
Tony
Nov 15 '05 #1
4 5253
Amazing what sort of stunts programmers always want to do :)

As I understand: you app has different threads. Each thread can modify
The One and Only file. But if one thread is busy with that file, all
other threads should have R access to that file. So, there's always only
one thread with RW access - or none. Is that correct? If so, I would
think you have some sort of mechanism to synchronise the access to that
file. And if you have such a mechanism, only one thread will be able to
write to that file. So, what is the problem then? Try describing your
problem in more detail.

Tony Liu wrote:
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 create a new file handle each time is because those
different threads will be working on a different area of the file and I just
can't share a single master file handle.

Thanks in advance
Tony


Nov 15 '05 #2
Actually, all threads have RW access to the file. The file contains paged
data, therefore, one thread could be reading from page 1, while another
thread is writing to page 2, and also possibly another thread is writing to
page 3, etc.

My problem is that, since I must create a new file handle so that all thread
can have their own file pointer(they are working in different blocks of data
in the file), I must set the FileShare to FileShare.ReadWrite. Now this
actually works, but what I really want is to only allow RW sharing within my
process, and have the file locked from other process, so that other process
cannot open it while my process is working with the file.

Thanks
Tony Liu
"Antenna" <q1****************@hotmail.com> wrote in message
news:bv**********@news.worldonline.be...
Amazing what sort of stunts programmers always want to do :)

As I understand: you app has different threads. Each thread can modify
The One and Only file. But if one thread is busy with that file, all
other threads should have R access to that file. So, there's always only
one thread with RW access - or none. Is that correct? If so, I would
think you have some sort of mechanism to synchronise the access to that
file. And if you have such a mechanism, only one thread will be able to
write to that file. So, what is the problem then? Try describing your
problem in more detail.

Tony Liu wrote:
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 create a new file handle each time is because those different threads will be working on a different area of the file and I just can't share a single master file handle.

Thanks in advance
Tony

Nov 15 '05 #3
And why can't you share a single master file handle?

Tony Liu wrote:
Actually, all threads have RW access to the file. The file contains paged
data, therefore, one thread could be reading from page 1, while another
thread is writing to page 2, and also possibly another thread is writing to
page 3, etc.

My problem is that, since I must create a new file handle so that all thread
can have their own file pointer(they are working in different blocks of data
in the file), I must set the FileShare to FileShare.ReadWrite. Now this
actually works, but what I really want is to only allow RW sharing within my
process, and have the file locked from other process, so that other process
cannot open it while my process is working with the file.

Thanks
Tony Liu


Nov 15 '05 #4
Because more than one thread could access the file at the same time, if
thread A needs to read from the beginning of the file and thread B needs to
write to the end of the file at the same time, they need to have their own
handle instead of sharing the master file handle.

"Antenna" <q1****************@hotmail.com> wrote in message
news:c0**********@news.worldonline.be...
And why can't you share a single master file handle?

Tony Liu wrote:
Actually, all threads have RW access to the file. The file contains paged data, therefore, one thread could be reading from page 1, while another
thread is writing to page 2, and also possibly another thread is writing to page 3, etc.

My problem is that, since I must create a new file handle so that all thread can have their own file pointer(they are working in different blocks of data in the file), I must set the FileShare to FileShare.ReadWrite. Now this
actually works, but what I really want is to only allow RW sharing within my process, and have the file locked from other process, so that other process cannot open it while my process is working with the file.

Thanks
Tony Liu

Nov 15 '05 #5

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

Similar topics

3
by: Alex | last post by:
Hi all, I want to write a "File sharing system". Is posssible with socket and thread create multisuer connection at the same time ? or is wrong my idea?? thanks
18
by: Conrad F | last post by:
Hello all, I am waiting for receipt of files in a directory. I use the FileSystemWatcher to detect when files arrive in said folder. I need to read the data from these files ASAP but the files...
5
by: BPearson | last post by:
Hello I would like to have several sites share a single web.config file. To accomplish this, I would point the root of these sites to the same folder. Is there any reason why I might not want to...
6
by: Tom C. | last post by:
Hi I'm trying to create a web form that will print a MS Word doc from the web form. I'm using VB.net. This is the code example Dim WordApp As New Word.Applicati Private Sub...
3
by: jcrouse | last post by:
Is it possible more multiple controls (labels) to share the code from one context menu. I have 32 labels on a form and don't want to add 32 context menu controls. Where might I find information on...
1
by: dwainew | last post by:
Problem: I'd like to archive off the contents of a text file. However, other processes may have the file open, so MoveTo(newfilepath) can't be done, as far as I've found. Start with a 5 MB...
35
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from...
36
by: pearl146 | last post by:
Hi, I have some database files (.MDF, .LDF,...) on the server. When I try to delete them, the warning "Cannot delete file: There has been a sharing violation. The source or destination file may...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.