473,480 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Thread Safety

Thread Safety

I wrote a small class library written in C# which writes log messages
to a log file.
Everything works fine when one ASP.net application uses this dll to
write text strings.
The problem starts when 2 or more applications ( ASP.net or Console )
uses this dll simultaneously and try to write a lot of messages (
around 10000 ).

I get error that the text file is being used by other process.
In my final application this dll will be used for logging and it should
handle unlimited number of user .

I want to make it completely thread safe so that any number of
different applications can parallaly write to the same text file.

I tried to use lock and synchronized methods etc but nothing is
working.
For writing to the text file I am using StreamWriter class.
I am using VS2005

Can anybody help?

Regards
Akash

Jul 11 '06 #1
3 2239
softwareakash wrote:
I get error that the text file is being used by other process.
In my final application this dll will be used for logging and it should
handle unlimited number of user .

I want to make it completely thread safe so that any number of
different applications can parallaly write to the same text file.

I tried to use lock and synchronized methods etc but nothing is
working.
lock/Monitor only works within the current process. Use the Mutex class
for interprocess synchronization.

hth,
Max
Jul 11 '06 #2
softwareakash <so***********@gmail.comwrote:

<snip>
I want to make it completely thread safe so that any number of
different applications can parallaly write to the same text file.
This isn't a matter of *thread* safety, it's a matter of *process*
safety. You could (as Markus mentioned) use mutexes. Another
alternative is to have a single process running which actually writes
to the files, and use sockets (or some other IPC channel) to make the
other applications talk to that process.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 11 '06 #3
why re-invent the wheel? really? the wheel already works in the situation
you want it and it's been tested in the enterprise. That wheel is the
enterprise library logging application block. it will log simple and
efficiently and scale well across process. finally, it's a free utility
available from microsoft.

--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------
"softwareakash" <so***********@gmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
Thread Safety

I wrote a small class library written in C# which writes log messages
to a log file.
Everything works fine when one ASP.net application uses this dll to
write text strings.
The problem starts when 2 or more applications ( ASP.net or Console )
uses this dll simultaneously and try to write a lot of messages (
around 10000 ).

I get error that the text file is being used by other process.
In my final application this dll will be used for logging and it should
handle unlimited number of user .

I want to make it completely thread safe so that any number of
different applications can parallaly write to the same text file.

I tried to use lock and synchronized methods etc but nothing is
working.
For writing to the text file I am using StreamWriter class.
I am using VS2005

Can anybody help?

Regards
Akash

Jul 13 '06 #4

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

Similar topics

4
6627
by: Jonathan Burd | last post by:
Greetings everyone, Here is a random string generator I wrote for an application and I'm wondering about the thread-safety of this function. I was told using static and global variables cause...
9
2074
by: Alexander Fleck | last post by:
Hi, I' ve to make a software module thread safe. I know how to realize that and what' re the main topics of thread safety. But I don' t know how thread safety can be tested. I read about a test...
4
2772
by: The Crow | last post by:
for example i have static readonly SqlParameter and i want to clone them at runtime. as clone operation will not write to SqlParameter object, just reading, should i lock that object during read...
22
37673
by: Brett | last post by:
I have a second thread, t2, that errors out and will stop. It's status is then "Stopped". I try to start t2 from thread 1, t1, by checking If t2.threadstate = "Stopped" Then t2.start() ...
4
2542
by: Warren Sirota | last post by:
Hi, I've got a method that I want to execute in a multithreaded environment (it's a specialized spider. I want to run a whole bunch of copies at low priority as a service). It works well running...
6
3122
by: fniles | last post by:
I am using VB.NET 2003 and a socket control to receive and sending data to clients. As I receive data in 1 thread, I put it into an arraylist, and then I remove the data from arraylist and send it...
1
3604
by: paul.hester | last post by:
Hi all, All of the classes in my DAL are static, with constants defining the stored procedures and parameters. I've been having some problems with my site which makes me wonder if there's a...
13
3558
by: arun.darra | last post by:
Are the following thread safe: 1. Assuming Object is any simple object Object* fn() { Object *p = new Object(); return p; } 2. is return by value thread safe?
0
4087
by: Graham Wideman | last post by:
Folks: Can anyone tell me what controls php's "thread safety" feature? I have an installation where phpinfo() is showing Thread safety: enabled, whereas I need it disabled in order to work...
13
11414
by: Henri.Chinasque | last post by:
Hi all, I am wondering about thread safety and member variables. If I have such a class: class foo { private float m_floater = 0.0; public void bar(){ m_floater = true; }
0
6908
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...
0
7048
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
6956
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
5342
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
2997
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
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
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 ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
183
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.