It look like I have a JIT error (another one :/) :
I have this piece of code :
private Boolean m_bIsLoaded = false;
public Boolean IsLoaded
{
get { return this.m_bIsLoaded; }
set { this.m_bIsLoaded = value; }
}
public long DocGedCourrier {
get {
if ((this.IsLoaded == false)) {
this.Load();
}
return this.GetInt64Value("ID_DOCGEDCOURRIER");
}
set {
this.SetValue("ID_DOCGEDCOURRIER", value);
NotifyPropertyChanged("DocGedCourrier");
}
}
I'm running a windows service on a x64 platform (Windows XP service Pack 3) in debug, with no optimization.
When I attached the debugger remotely and I put a breakpoint on the this.Load() method, the debugger stop. If I look the value of this.IsLoaded, it's return True.
If I run the service without the debugger attached, the Load() function is always called even if IsLoaded == True.
If I run the service with the debugger attached, the Load() is not called when I debug step-by-step.
If I run the service on a x86 platform (Windows XP service Pack 3), it's work perfectly, with and without the debugger attached.
There is no way m_bIsLoaded could change because m_bIsLoaded is only set with the IsLoaded property and the set { this.m_bIsLoaded = value; } is only called once, with a IsLoaded = true.
I'm 99.99% sure it's a JIT error, because I already had this kind of problem (see also Variable is not incrementing in C# Release x64).
My question is :
How could I detect this kind of problem and avoid them definitely ?
Thank you,
Edit :
I add a lock to ensure IsLoaded is not modified by another thread :
public readonly Object Lock = new Object();
public virtual Object Load()
{
lock (Lock)
{
if ((IsLoaded))
{
return this;
}
}
...
}
public Boolean IsLoaded
{
get { return this.m_bIsLoaded; }
set
{
lock (Lock)
{
this.m_bIsLoaded = value;
}
}
}
It did not solve the problem. As you can see in this screen shoot : http://img15.hostingpics.net/pics/125986Screenshoot.jpg . Return this is not call even if IsLoaded is set to True.
I exclude the multi-thread access possibility. by the way, IsLoaded is only set to false when the field is initialised. If IsLoaded is True, there is no way it could have the False value anymore in my code.
What can I do to prevent this ?