Click here to Skip to main content
15,908,675 members
Home / Discussions / C#
   

C#

 
GeneralRe: About Hashtables Pin
Spunky Coder1-Apr-08 19:54
Spunky Coder1-Apr-08 19:54 
GeneralRe: About Hashtables Pin
Harvey Saayman1-Apr-08 22:26
Harvey Saayman1-Apr-08 22:26 
QuestionHow to perform cut,delete operation in bitmap? Pin
Aravinthan1-Apr-08 18:51
Aravinthan1-Apr-08 18:51 
GeneralConfused with the Equals() of Object class [modified] Pin
Darmi1-Apr-08 17:48
Darmi1-Apr-08 17:48 
GeneralRe: Confused with the Equals() of Object class Pin
N a v a n e e t h1-Apr-08 20:38
N a v a n e e t h1-Apr-08 20:38 
GeneralRe: Confused with the Equals() of Object class Pin
carbon_golem2-Apr-08 2:48
carbon_golem2-Apr-08 2:48 
GeneralSite Personalization - UserID from the asp_net Profile table Pin
karmasol1-Apr-08 17:46
karmasol1-Apr-08 17:46 
QuestionProblem with Singleton Pattern Pin
Zero Destiny1-Apr-08 17:39
professionalZero Destiny1-Apr-08 17:39 
Alright now I have a really strange bug thats popping up in my code.

Some Before hand details.

Language: C#
Framework Version: 2.0
IDE: Visual Studio 2008 Team Edition

Now to the real problem

I'm working on a project and because it is based on a plugin engine I have to pass the current context of the system to the plugin. So
I use the Singleton Pattern alot. Basic snippet below.


public class SomeClass
{
    private static SomeClass _current = null;

    public static SomeClass Current
    {
       get
       {
          if(_current == null)
          {
            _current = new SomeClass();
          }

          return _current;
       }
    }

    public SomeClass()
    {
      //Do some stuff
    }

}



Now that seems pretty normal and correct to me but this is how it executes. Just watch the little arrow.


public class SomeClass
{
    private static SomeClass _current = null;

--> public static SomeClass Current
    {
       get
       {
          if(_current == null)
          {
            _current = new SomeClass();
          }

          return _current;
       }
    }

    public SomeClass()
    {
      //Do some stuff
    }

}



Ok good so far.


public class SomeClass
{
    private static SomeClass _current = null;

    public static SomeClass Current
    {
       get
 -->   {
          if(_current == null)
          {
            _current = new SomeClass();
          }

          return _current;
       }
    }

    public SomeClass()
    {
      //Do some stuff
    }

}



Still ok


public class SomeClass
{
    private static SomeClass _current = null;

    public static SomeClass Current
    {
       get
       {
 -->      if(_current == null)
          {
            _current = new SomeClass();
          }

          return _current;
       }
    }

    public SomeClass()
    {
      //Do some stuff
    }

}



Alright we are there..

public class SomeClass
{
    private static SomeClass _current = null;

    public static SomeClass Current
    {
       get
       {
          if(_current == null)
          {
            _current = new SomeClass();
          }

 -->       return _current;
       }
    }

    public SomeClass()
    {
      //Do some stuff
    }

}



Thats right.. It evaluates _current == null as false but clearly I have it assigned to null.. and it never executes my constructor.
So I have no idea whats going on.

By the way this happens in a .DLL thats being referenced by a web project and I first noticed this issue when testing out a class with one
of my unit tests.

So basicly what I'm asking is if someone with more knowledge than me can help me figure out whats going on cause no matter what I do it always seems to skip that _current = new SomeClass() statement.

But whats even more confusing is I have another class thats exactly the same (except the named of course) and it executes and works fine. So I dont know.<
GeneralRe: Problem with Singleton Pattern Pin
Simon P Stevens1-Apr-08 22:25
Simon P Stevens1-Apr-08 22:25 
GeneralRe: Problem with Singleton Pattern Pin
Rob Philpott1-Apr-08 22:49
Rob Philpott1-Apr-08 22:49 
GeneralRe: Problem with Singleton Pattern Pin
Rob Philpott1-Apr-08 22:51
Rob Philpott1-Apr-08 22:51 
GeneralRe: Problem with Singleton Pattern Pin
carbon_golem2-Apr-08 3:03
carbon_golem2-Apr-08 3:03 
GeneralRe: Problem with Singleton Pattern Pin
Zero Destiny2-Apr-08 4:22
professionalZero Destiny2-Apr-08 4:22 
QuestionHow to pass a parameter in an event Pin
Silvyster1-Apr-08 16:08
Silvyster1-Apr-08 16:08 
GeneralRe: How to pass a parameter in an event Pin
PandemoniumPasha1-Apr-08 17:38
PandemoniumPasha1-Apr-08 17:38 
GeneralRe: How to pass a parameter in an event Pin
Silvyster1-Apr-08 22:12
Silvyster1-Apr-08 22:12 
GeneralRe: How to pass a parameter in an event Pin
J4amieC1-Apr-08 22:30
J4amieC1-Apr-08 22:30 
GeneralInfos, links, best practice etc. for programming a webservice Pin
stephan_0071-Apr-08 12:02
stephan_0071-Apr-08 12:02 
GeneralRe: Infos, links, best practice etc. for programming a webservice Pin
KaptinKrunch1-Apr-08 14:05
KaptinKrunch1-Apr-08 14:05 
GeneralRe: Infos, links, best practice etc. for programming a webservice Pin
Rob Philpott1-Apr-08 22:45
Rob Philpott1-Apr-08 22:45 
Question(XML) Editing a single element within a node Pin
Stupefy1-Apr-08 10:13
Stupefy1-Apr-08 10:13 
GeneralRe: (XML) Editing a single element within a node Pin
damianrda1-Apr-08 10:56
damianrda1-Apr-08 10:56 
GeneralRe: (XML) Editing a single element within a node Pin
Stupefy1-Apr-08 11:03
Stupefy1-Apr-08 11:03 
GeneralRe: (XML) Editing a single element within a node Pin
led mike1-Apr-08 11:04
led mike1-Apr-08 11:04 
GeneralRe: (XML) Editing a single element within a node Pin
led mike1-Apr-08 10:59
led mike1-Apr-08 10:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.