StreamWriter and Multi-threading

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • José Joye

    #1

    StreamWriter and Multi-threading

    I have 2 threads using the same StreamWriter (obtained from
    FileInfo.Append Text).
    This first thread will always use the WriteLine() method and the second
    thread will always use the Flush() method.
    At the present, I have protected the access to the StreamWriter using a
    Lock() section.

    Is this really particular case, is this necessary?
    What could be the implication if I remove the Lock() section?

    Thanks,
    José


  • Peter Q

    #2
    Re: StreamWriter and Multi-threading

    While one sw is writing to the file, the other one is flushing the buffer?
    What are you trying to achieve here?

    regards,
    Peter


    "Jos?Joye" <jose.joye@__No _SPam__bluewin_ _maPS_oN__.ch> wrote in message
    news:%238WsMOgg DHA.408@TK2MSFT NGP10.phx.gbl.. .[color=blue]
    > I have 2 threads using the same StreamWriter (obtained from
    > FileInfo.Append Text).
    > This first thread will always use the WriteLine() method and the second
    > thread will always use the Flush() method.
    > At the present, I have protected the access to the StreamWriter using a
    > Lock() section.
    >
    > Is this really particular case, is this necessary?
    > What could be the implication if I remove the Lock() section?
    >
    > Thanks,
    > Jos?
    >
    >[/color]


    Comment

    • José Joye

      #3
      Re: StreamWriter and Multi-threading

      In fact the client using my class needs to write information in a file.
      However, it has really little time at disposal (I can not flush information
      synchrously, it will take too much time). Therefore, the method called by
      the client will make a writeline (which does not flush and therefore it is
      quick) it will send set an event for an async. thread telling some info
      needs to be flush.

      Hope this sounds clear?

      Do you have an answer to my question?
      José


      "Peter Q" <pmouse@cogeco. ca> a écrit dans le message de
      news:Hr6cb.1214 2$Gr.738903@rea d1.cgocable.net ...[color=blue]
      > While one sw is writing to the file, the other one is flushing the buffer?
      > What are you trying to achieve here?
      >
      > regards,
      > Peter
      >
      >
      > "Jos?Joye" <jose.joye@__No _SPam__bluewin_ _maPS_oN__.ch> wrote in message
      > news:%238WsMOgg DHA.408@TK2MSFT NGP10.phx.gbl.. .[color=green]
      > > I have 2 threads using the same StreamWriter (obtained from
      > > FileInfo.Append Text).
      > > This first thread will always use the WriteLine() method and the second
      > > thread will always use the Flush() method.
      > > At the present, I have protected the access to the StreamWriter using a
      > > Lock() section.
      > >
      > > Is this really particular case, is this necessary?
      > > What could be the implication if I remove the Lock() section?
      > >
      > > Thanks,
      > > Jos?
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • José Joye

        #4
        Re: StreamWriter and Multi-threading

        In fact the client using my class needs to write information in a file.
        However, it has really little time at disposal (I can not flush information
        synchrously, it will take too much time). Therefore, the method called by
        the client will make a writeline (which does not flush and therefore it is
        quick) it will send set an event for an async. thread telling some info
        needs to be flush.

        Hope this sounds clear?

        Do you have an answer to my question?
        José


        "Peter Q" <pmouse@cogeco. ca> a écrit dans le message de
        news:Hr6cb.1214 2$Gr.738903@rea d1.cgocable.net ...[color=blue]
        > While one sw is writing to the file, the other one is flushing the buffer?
        > What are you trying to achieve here?
        >
        > regards,
        > Peter
        >
        >
        > "Jos?Joye" <jose.joye@__No _SPam__bluewin_ _maPS_oN__.ch> wrote in message
        > news:%238WsMOgg DHA.408@TK2MSFT NGP10.phx.gbl.. .[color=green]
        > > I have 2 threads using the same StreamWriter (obtained from
        > > FileInfo.Append Text).
        > > This first thread will always use the WriteLine() method and the second
        > > thread will always use the Flush() method.
        > > At the present, I have protected the access to the StreamWriter using a
        > > Lock() section.
        > >
        > > Is this really particular case, is this necessary?
        > > What could be the implication if I remove the Lock() section?
        > >
        > > Thanks,
        > > Jos?
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...