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

  • Home
  • SEARCH
  • 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 572569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:37:35+00:00 2026-05-13T13:37:35+00:00

We have an application that runs a routine like: protected string _largeFile; Execute() //this

  • 0

We have an application that runs a routine like:

protected string _largeFile;

Execute()   //this executes in basically an infinite loop.
{
    _largeFile = "";
    DoStuff();
    DoStuff();
    _largeFile = "ReallyBigString"; //sometimes 4-5Mb
      if(_largeFile != "")
      {
       RaiseEvent();
      }
    DoStuff();
    DoSTuff();
    Thread.Sleep(5000);  //wait 5 seconds;
//repeat
}

CatchEvent()
{
     SendLargeFileToWebService(_largeFile);
}

This code executes on a client PC that we can’t control. The code basically gets a large file and sends it back to our server. The issue is that sometimes the largeFile returned to the web service is blank. We have researched this for some time, and have been unable to determine how this happens.

The only solution that seems to have any merit is that the time it takes to RaiseTheEvent is taking so long that when the Execute methods is executing a subsequent time, the class level _largeFile variable is cleared before the SendLargeFileToWebService is able to do this.

My question: Is this even plausible? The developer that wrote the code defends that the reason for the class level variable was to avoid having to copy an instance variable and pass it around to the new thread (presumably the thread the event executes on). Does that seem like the right approach? There may not be a silver bullet answer to this, so if anyone can explain to me some standard for instance-event arguemnts vs. class variables when raising events I would appreciate it. I am also curious if the proposed issue is even plausible. Are their know issues when evaluating large strings from different threads.

  • 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-13T13:37:36+00:00Added an answer on May 13, 2026 at 1:37 pm

    I’m a little unclear about the scenario. But from your description it seems the Execute method is called from multiple threads. If so then yes you certainly have a bug because if at any time two Execute methods are running you will have a race condition over _largeFile.

    There are 2 ways to fix this

    1. Pass the contents of _largeFile as a parameter to Execute
    2. Add a lock inside the execute method to prevent multiple threads from executing it at the same time.

    The argument that they didn’t want to pass the variable around smacks of laziness and IMHO should not be counted as a valid argument.

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

Sidebar

Ask A Question

Stats

  • Questions 420k
  • Answers 420k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This query evaluates all combinations of id1, id2 and id3… May 15, 2026 at 10:44 am
  • Editorial Team
    Editorial Team added an answer The algorithm for determining the tab order is here:-   … May 15, 2026 at 10:44 am
  • Editorial Team
    Editorial Team added an answer I would recommend defining the two formats in classes, rather… May 15, 2026 at 10:44 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.