Re: [ADVANCED-DOTNET] C# Singleton; foot in mouth

2007-07-08 Thread Ron Young
Further reference: DownloadManager : BaseMangager { } Problem is that the concept of "manager" should be allowed to work with many different providers. Like another provider might be an "audit provider", or a "calculate charge per request" provider. Our architecture is the stage above, and I thi

Re: [ADVANCED-DOTNET] C# Singleton; foot in mouth

2007-07-08 Thread Ron Young
Yes, thanks. But is it a singleton. internal abstract class BaseManager where I: IEntityProvider { private static I _provider = default(I); private static object _syncLock = new object(); protected static I Provider { if (_provider == null)

[ADVANCED-DOTNET] How to use the CLR Profiler

2007-07-08 Thread Thokala, Sreeramudu (GE Healthcare)
Hi, We are trying to use the CLR Profiler. We used the procedure given at the lnk http://msdn2.microsoft.com/en-us/library/ms979205.aspx It always shows the below Dialog with test" Waiting for Application to start common language runtime. Thanks Sreeram ===

Re: [ADVANCED-DOTNET] C# Singleton; foot in mouth

2007-07-08 Thread Greg Young
Ron see previous comments in your other post about gaurentees in ECMA 335 about cctor execution. It fits wonderfully with the sigleton pattern as the type initializer is only run once and will be before any method is called (on a reference type). On 7/9/07, Ron Young <[EMAIL PROTECTED]> wrote:

Re: [ADVANCED-DOTNET] C# Singleton

2007-07-08 Thread Greg Young
I believe you are referring to the simpler version of .. // .NET Singleton sealed class Singleton { private Singleton() {} public static readonly Singleton Instance = new Singleton(); } This is ok providing you dont care if beforefieldinit is set. This will cause the JIT to load the stati

Re: [ADVANCED-DOTNET] C# Singleton; foot in mouth

2007-07-08 Thread Ron Young
I just read this... http://www.yoda.arachsys.com/csharp/singleton.html Third version Wow, that looks like double check lock and he says its bad. This sucks. I thought that was a pattern. Ron -Original Message- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf

Re: [ADVANCED-DOTNET] C# Singleton

2007-07-08 Thread Ron Young
That was the first pattern I learned from but I read Brad Abrams on Concurrency management and I believe he has a simpler pattern code-wise: http://msdn.microsoft.com/msdnmag/issues/05/08/Concurrency/ I posted earlier on this and all signs point to yes. It's an interesting topic. Ron -Origi

[ADVANCED-DOTNET] C# Singleton

2007-07-08 Thread Miika Mäkinen
Hi guys, Which singleton implementation do you normally use? I've been using number five from http://www.yoda.arachsys.com/csharp/singleton.html but reading http://msdn2.microsoft.com/en-us/library/ms954629.aspx I'm understanding that a simpler implementation works just the same? Cheers, Miika =

Re: [ADVANCED-DOTNET] static variable, static property accessor

2007-07-08 Thread Ron Young
Thanks for that...I'll re-read it again. Ron -Original Message- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of J. Merrill Sent: Sunday, July 08, 2007 10:47 PM To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: Re: [ADVANCED-DOTNET] static variable, static p

Re: [ADVANCED-DOTNET] static variable, static property accessor

2007-07-08 Thread Ron Young
Thanks for all the info, good stuff. Interesting too, double-check lock in C# and all, CLI reference. Ron -Original Message- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Greg Young Sent: Sunday, July 08, 2007 10:57 PM To: ADVANCED-DOTNET@DISCUSS.DEVELOP

Re: [ADVANCED-DOTNET] static variable, static property accessor

2007-07-08 Thread Greg Young
Static constructors are gaurenteed in ECMA 335 to only be run once even in the case of multiple threads accessing the class for the first time concurrently. I quote from the spec. 10.5.3.1 Type initialization guarantees The CLI shall provide the following guarantees regarding type initialization

Re: [ADVANCED-DOTNET] static variable, static property accessor

2007-07-08 Thread J. Merrill
I'm not questioning the accuracy of your statement, but I don't see a connection between "static constructors can only be called once" and "static constructors have an implicit lock." You seem to be saying that Ron Young's code will work but is doing more work than is necessary because of the

Re: [ADVANCED-DOTNET] static variable, static property accessor

2007-07-08 Thread Peter Ritchie
Yes, it's thread-safe. Static constructors have an implicit lock (they can only be called once, so other threads must be locked out until the constructor is complete, should it currently be running). You've essentially implemented a singleton... -- Peter On Sun, 8 Jul 2007 18:00:19 -0500, Ron Y

[ADVANCED-DOTNET] static variable, static property accessor

2007-07-08 Thread Ron Young
Say I have this class, I'm copying/pasting from Visual Studio: class StaticObject_VariableHolder { private static object _sharedVariable; private static object _syncRoot = new object(); private StaticObject_VariableHolder() { } p