473,320 Members | 1,868 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,320 software developers and data experts.

Opening a file (log file) for write only but need a lock on it.

UJ
What's the easiest/best way to open a single file from multiple applications
but so only one can read it at a time? I tried a mutex but had problems. I
noticed there is something called a ReaderWriter class but it says it's best
for reads.

I'll never be reading the file.....

TIA - Jeff.
Sep 11 '06 #1
4 1673
If you want to keep the file open and they are all on the same machine your
initial thought of using a mutex seems correct ...

What were your problems with using a mutex to define a critical section when
writing to the file?

Cheers,

Greg
"UJ" <fr**@nowhere.comwrote in message
news:ua**************@TK2MSFTNGP05.phx.gbl...
What's the easiest/best way to open a single file from multiple
applications but so only one can read it at a time? I tried a mutex but
had problems. I noticed there is something called a ReaderWriter class but
it says it's best for reads.

I'll never be reading the file.....

TIA - Jeff.


Sep 11 '06 #2
UJ
Every once in a while the mutex seemed to get lost by somebody so that then
nobody could access to the file.

Of course, since then I've cleaned up the code a lot so it may be fixed now.
I just have tried it.

I guess unless somebody else has a better idea, I'll put the mutex back in
and try it to see what would happen.

Thanks.

"Greg Young" <dr*******************@hotmail.comwrote in message
news:O4**************@TK2MSFTNGP05.phx.gbl...
If you want to keep the file open and they are all on the same machine
your initial thought of using a mutex seems correct ...

What were your problems with using a mutex to define a critical section
when writing to the file?

Cheers,

Greg
"UJ" <fr**@nowhere.comwrote in message
news:ua**************@TK2MSFTNGP05.phx.gbl...
>What's the easiest/best way to open a single file from multiple
applications but so only one can read it at a time? I tried a mutex but
had problems. I noticed there is something called a ReaderWriter class
but it says it's best for reads.

I'll never be reading the file.....

TIA - Jeff.



Sep 11 '06 #3
UJ
What about using the lock keyword?

Do something like

lock this
{
OpenFile
WriteToFile
CloseFile
}

I'll be using the same object everywhere to do the actual writing....

J.

"UJ" <fr**@nowhere.comwrote in message
news:e5**************@TK2MSFTNGP03.phx.gbl...
Every once in a while the mutex seemed to get lost by somebody so that
then nobody could access to the file.

Of course, since then I've cleaned up the code a lot so it may be fixed
now. I just have tried it.

I guess unless somebody else has a better idea, I'll put the mutex back in
and try it to see what would happen.

Thanks.

"Greg Young" <dr*******************@hotmail.comwrote in message
news:O4**************@TK2MSFTNGP05.phx.gbl...
>If you want to keep the file open and they are all on the same machine
your initial thought of using a mutex seems correct ...

What were your problems with using a mutex to define a critical section
when writing to the file?

Cheers,

Greg
"UJ" <fr**@nowhere.comwrote in message
news:ua**************@TK2MSFTNGP05.phx.gbl...
>>What's the easiest/best way to open a single file from multiple
applications but so only one can read it at a time? I tried a mutex but
had problems. I noticed there is something called a ReaderWriter class
but it says it's best for reads.

I'll never be reading the file.....

TIA - Jeff.




Sep 11 '06 #4
"What's the easiest/best way to open a single file from multiple
applications "

You said that you were using multiple applications ... lock() only works
within the given appdomain (except in one odd circumstance which I highly
doubt you are using) .. It will not work between multiple processes ever as
the processes cannot possible have access to the same instance, remoting may
make you think you have access to the same object but in reality each app
domain has its own unique proxy (which is what would have to be locked on).

Cheers,

Greg

"UJ" <fr**@nowhere.comwrote in message
news:u4**************@TK2MSFTNGP04.phx.gbl...
What about using the lock keyword?

Do something like

lock this
{
OpenFile
WriteToFile
CloseFile
}

I'll be using the same object everywhere to do the actual writing....

J.

"UJ" <fr**@nowhere.comwrote in message
news:e5**************@TK2MSFTNGP03.phx.gbl...
>Every once in a while the mutex seemed to get lost by somebody so that
then nobody could access to the file.

Of course, since then I've cleaned up the code a lot so it may be fixed
now. I just have tried it.

I guess unless somebody else has a better idea, I'll put the mutex back
in and try it to see what would happen.

Thanks.

"Greg Young" <dr*******************@hotmail.comwrote in message
news:O4**************@TK2MSFTNGP05.phx.gbl...
>>If you want to keep the file open and they are all on the same machine
your initial thought of using a mutex seems correct ...

What were your problems with using a mutex to define a critical section
when writing to the file?

Cheers,

Greg
"UJ" <fr**@nowhere.comwrote in message
news:ua**************@TK2MSFTNGP05.phx.gbl...
What's the easiest/best way to open a single file from multiple
applications but so only one can read it at a time? I tried a mutex but
had problems. I noticed there is something called a ReaderWriter class
but it says it's best for reads.

I'll never be reading the file.....

TIA - Jeff.




Sep 11 '06 #5

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

Similar topics

6
by: Pekka Niiranen | last post by:
Hi, I have used the following example from win32 extensions: -----SCRIPT STARTS---- import win32file import win32con import win32security import pywintypes
6
by: joethis | last post by:
Is there a way to make sure that a file is already in use using asp? For instance, if one person has opened a file and is about to write to it; then is there a way to keep another user from...
4
by: HNguyen | last post by:
Hi, I have a Web application in ASP.NET. My Application allows the users upload files into the server after checking their user names and passwords. For each transaction, the Web program will...
4
by: Omko H | last post by:
I am trying to open %windir%\pfirewall.log. and I just can't get it to work (I am a absolute newbie to VB.net) the strange thing is that notepad is perfectly able to view the file. but my code...
1
by: lactaseman | last post by:
While I know this is not the correct venue... I realize this is of little to no importance to most out there... however, if I had found this in my initial searches, I would have used this. So, as...
3
by: UJ | last post by:
Has anybody done anything with using log4net where you have multiple programs on a single machine writing to the same log file? TIA - J.
7
by: mistral | last post by:
I use htaccess to protect directory and granting access to download file only for the authorized users. Just want implement simple PHP file download counter for single file. I need track the number...
1
by: gallois | last post by:
hello everyone, i've been trying to write something that checks the inputs from the possible devices where a mouse can be connected (debian/linux) in order to make it configure the system...
2
by: WingSiu | last post by:
I am writing a Logging util for my ASP.NET application. I am facing mulit process problem. I developed a class LogFactory, and have a method called Get_Logger to create a FileLogger, which will...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.