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 7743371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:31:01+00:00 2026-06-01T09:31:01+00:00

There’s a code that reads a file and makes some calculating operations with its

  • 0

There’s a code that reads a file and makes some calculating operations with its content in another thread using the classes Task and StreamReader.

 Task t= new Task(() => DoSomeWork(myFile));
 t.Start();

But inspite of the file is immutable sometimes I’m getting the different results! Why? What should I do to resolve it?

  • 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-06-01T09:31:02+00:00Added an answer on June 1, 2026 at 9:31 am

    You’ve clearly got something inside DoSomeWork() that is not thread safe. The most likely candidate for this is some static code, since that would mean that there’s only one copy of that particular piece of code in memory. One instance of DoSomeWork() could get context switched out, and another instance would then pick up on the state of the static method, giving you some unpredictable results.

    Other things could include improper use of dependency injection, a singleton object that’s being shared, certain libraries being improperly used as asynchronous, or a couple other things – this is what Drew was talking about when he asked for more information.

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

Sidebar

Related Questions

There is a text file with 1,000,000 lines of code floating around and Ctrl+F
There is a conversion process that is needed when migrating Visual Studio 2005 web
There is a field in my company's Contacts table. In that table, there is
There are numerous libraries providing Linq capabilities to C# code interacting with a MySql
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
There is a website called Gild.com that has different coding puzzles/challenges for users to
There is no doubt that MonoTouch is one of the great cross-compiler(s). Similarly, SenchaTouch
There was a thread on this in comp.lang.javascript recently where victory was announced but
There is a class that's a fully fledged UIViewController and when that page loads

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.