quick work with files at web-services

Discussion in 'ASP .Net Web Services' started by Evgenia, Nov 22, 2006.

  1. Evgenia

    Evgenia Guest

    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.
     
    Evgenia, Nov 22, 2006
    #1
    1. Advertising

  2. "Evgenia" <> wrote in message
    news:...
    > 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
     
    John Saunders, Nov 22, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nick
    Replies:
    1
    Views:
    6,264
    Alvin Bruney - ASP.NET MVP
    Sep 12, 2005
  2. Replies:
    2
    Views:
    452
  3. JKop
    Replies:
    11
    Views:
    936
  4. David Portabella

    Web Services in Java- Quick Start Tutorial

    David Portabella, Jul 9, 2010, in forum: Java
    Replies:
    0
    Views:
    410
    David Portabella
    Jul 9, 2010
  5. John
    Replies:
    4
    Views:
    502
Loading...

Share This Page