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.