quick work with files at web-services

E

Evgenia

I'm sorry for an uncertain question, but I can't ask it better. :(

I've got a web-service, which method invokes very-very often, so I have to
battle for every millisecond.

Method does next:
try
{
/* main code here */
lock(this) // writing in text log file
{
FileInfo f = new FileInfo(file name); // file name contains date and time
to an hour
StreamWriter writer = f.AppendText();
writer.WriteLine(logline);
writer.Close();
}
}
catch (Exception ex)
{
lock(this) // writing in text error-log file
{
FileInfo f = new FileInfo(file name); // file name contains date and time
to an millisecond
StreamWriter writer = f.AppendText();
writer.WriteLine(errorline);
writer.Close();
}
}

Tha most often exception is:
The process cannot access the file ... because it is being used by another
process

I should think out how to accelerate this scheme and minimize the quantity
of exception as far as possible, and at the same time not lose any log
recording and finale speed of method's execution.

What can I do?
Please, advise, how should such tasks be solved in systems with high load.

Thank you for any help in advance and sorry for my bad english.
 
J

John Saunders

Evgenia said:
I'm sorry for an uncertain question, but I can't ask it better. :(

I've got a web-service, which method invokes very-very often, so I have to
battle for every millisecond.

Method does next:
try
{
/* main code here */
lock(this) // writing in text log file
{

On every web method call, an instance of your web service is created and
later destroyed. There will never be more than one thread able to access
"this", so lock(this) does you no good.

Try:

private static object _locker = new object();

....
lock(_locker)
{
....
}

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top