Click here to Skip to main content
15,914,111 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: .NET Windows.Forms programs on Linux Pin
Heath Stewart18-Jul-03 22:26
protectorHeath Stewart18-Jul-03 22:26 
GeneralRe: .NET Windows.Forms programs on Linux Pin
Nathan Brown18-Jul-03 22:59
Nathan Brown18-Jul-03 22:59 
GeneralRe: .NET Windows.Forms programs on Linux Pin
Heath Stewart20-Jul-03 5:45
protectorHeath Stewart20-Jul-03 5:45 
GeneralRe: .NET Windows.Forms programs on Linux Pin
igor196021-Jul-03 12:37
igor196021-Jul-03 12:37 
GeneralRe: .NET Windows.Forms programs on Linux Pin
Heath Stewart21-Jul-03 16:57
protectorHeath Stewart21-Jul-03 16:57 
GeneralRe: .NET Windows.Forms programs on Linux Pin
jparsons24-Jul-03 15:10
jparsons24-Jul-03 15:10 
GeneralRe: .NET Windows.Forms programs on Linux Pin
Rocky Moore23-Jul-03 1:51
Rocky Moore23-Jul-03 1:51 
QuestionSingletons: Static ctors or Monitors? Pin
Heath Stewart18-Jul-03 2:56
protectorHeath Stewart18-Jul-03 2:56 
In a recent thread on the ndoc development list (for which I contribute), we were talking about the documentation of static constructors and that got me to thinking:

In most of my work, I use the approach for creating singleton objects by makeing a private constructor, then having a static property that returns an instance from which I can call other public or internal methods or properties. The whole thing looks like this:
public class Test
{
  private string text;
  private static Test instance;
  private static volatile object syncRoot = new Object();
  private Test()
  {
    this.text = "Test";
  }
  public static Test Instance
  {
    get
    {
      if (instance == null)
        lock (syncRoot)
          if (instance == null)
            instance = new Test();
      return instance;
    }
  }
  public string Text
  {
    get { return this.text; }
  }
}

This seems to be the method that Microsoft uses in the .NET BCL. And it works good. I do use static constructors in some things that aren't so sensative (like wrapping some GetDevice Win32 API code).

What I'm wondering is if static constructors work just as good as the method above? I haven't been able to find any documentation that discusses this in any detail, but my first reaction is that the first method is better because monitors are used and if would be thread-safe. But does the CLR invoke static constructors in a thread-safe manner on its own?

 

Reminiscent of my younger years...
10 LOAD "SCISSORS"
20 RUN

AnswerRe: Singletons: Static ctors or Monitors? Pin
Andy Smith18-Jul-03 11:37
Andy Smith18-Jul-03 11:37 
GeneralRe: Singletons: Static ctors or Monitors? Pin
Heath Stewart18-Jul-03 22:18
protectorHeath Stewart18-Jul-03 22:18 
GeneralRe: Singletons: Static ctors or Monitors? Pin
leppie19-Jul-03 2:10
leppie19-Jul-03 2:10 
GeneralPhotoshop-like toolbox issue Pin
lfsong17-Jul-03 2:32
lfsong17-Jul-03 2:32 
GeneralRe: Photoshop-like toolbox issue Pin
lfsong17-Jul-03 18:20
lfsong17-Jul-03 18:20 
GeneralRe: Photoshop-like toolbox issue Pin
lfsong20-Jul-03 4:02
lfsong20-Jul-03 4:02 
GeneralRe: Photoshop-like toolbox issue Pin
lfsong20-Jul-03 16:06
lfsong20-Jul-03 16:06 
GeneralRe: Photoshop-like toolbox issue Pin
lfsong22-Jul-03 2:29
lfsong22-Jul-03 2:29 
GeneralBuilding A Personal Webserver Pin
jmetcalf16-Jul-03 14:58
jmetcalf16-Jul-03 14:58 
GeneralRe: Building A Personal Webserver Pin
Heath Stewart17-Jul-03 1:25
protectorHeath Stewart17-Jul-03 1:25 
GeneralRun-Time Routines and .NET Framework Equivalents Pin
Nathan Blomquist15-Jul-03 4:35
Nathan Blomquist15-Jul-03 4:35 
GeneralRe: Run-Time Routines and .NET Framework Equivalents Pin
Frank Olorin Rizzi15-Jul-03 6:25
Frank Olorin Rizzi15-Jul-03 6:25 
GeneralRe: Run-Time Routines and .NET Framework Equivalents Pin
Nick Parker16-Jul-03 7:17
protectorNick Parker16-Jul-03 7:17 
GeneralRe: Run-Time Routines and .NET Framework Equivalents Pin
leppie16-Jul-03 7:33
leppie16-Jul-03 7:33 
GeneralRe: Windows Service Pin
Xiangyang Liu 刘向阳15-Jul-03 0:30
Xiangyang Liu 刘向阳15-Jul-03 0:30 
GeneralRe: Windows Service Pin
Xiangyang Liu 刘向阳15-Jul-03 0:55
Xiangyang Liu 刘向阳15-Jul-03 0:55 
GeneralRe: Windows Service Pin
Xiangyang Liu 刘向阳15-Jul-03 1:41
Xiangyang Liu 刘向阳15-Jul-03 1:41 

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.