Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6711007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:05:19+00:00 2026-05-26T08:05:19+00:00

My application has a logger which constantly logs data in a number of different

  • 0

My application has a logger which constantly logs data in a number of different files. Logging in each file is done synchronously using a StreamWriter object inside a “using” block. From time to time, I get an exception saying the file I’m trying to open is being used by another process.

Now the files I log into each has a unique name associated with the client id. My application is multi-threaded, but at any point in time only 1 instance of the client is active, so I am sure that the same file is not opened by more than 1 thread. However, my application does logs in the same file multiple times in say less than 1 second, for each log attempting to reopen the file. This leaves me to one other conclusion, that the “using” statement does not immediately close the file (even though I’ve read that it does for files), but only disposes it and waits for the GC to handle the closing.

Is my conclusion correct or is it something else that’s causing the exception?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:05:19+00:00Added an answer on May 26, 2026 at 8:05 am

    After exiting the using statement not only call to Close is made, but also to Dispose, cause using is nothing else then syntax sugare for

    try {
      //do stuff 
    }
    finally {
     //close, dispose stream object
    }
    

    So the problem is in multithreaded access, that somehow tries to access a file whom writer not yet disposed, which does not mean that using statement does not work, but means that it still has to finish it job.

    EDIT

    You can try to use ProcessExplorer to check the specified file handle ownership. Check out online help for how to do it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a MATLAB application which has many functions spread over different files. I
In an application I'm working on I've created a lightweight logger which has two
Our application has a file format similar to the OpenDocument file format (see http://en.wikipedia.org/wiki/OpenDocument
I basically want to write a customer logger/tracer which also logs the class and
I am maintaining an application which has been designed like this: messy code --abuses-->
I'm trying to create simple application with Xuggler, which has to encode sequence of
I have a Web Application which has Global_Asax and a Custom Error Page. When
I have an windows application (WPF) in which we are running on each login,
I've got a Rails application in which a small number of actions require significant
Application has an auxiliary thread. This thread is not meant to run all the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.