Click here to Skip to main content
15,915,336 members
Home / Discussions / C#
   

C#

 
GeneralRe: Convert HTML to PDF Stream into DB Pin
Alex Korchemniy13-Jan-04 4:48
Alex Korchemniy13-Jan-04 4:48 
GeneralRe: Convert HTML to PDF Stream into DB Pin
Heath Stewart13-Jan-04 5:32
protectorHeath Stewart13-Jan-04 5:32 
GeneralCustom permissions Pin
Hans Ruck13-Jan-04 1:43
Hans Ruck13-Jan-04 1:43 
GeneralRe: Custom permissions Pin
Heath Stewart13-Jan-04 5:30
protectorHeath Stewart13-Jan-04 5:30 
GeneralRe: Custom permissions Pin
Hans Ruck13-Jan-04 22:21
Hans Ruck13-Jan-04 22:21 
Generalaxwebbrowser excel mdicontainer Pin
mylitziname12-Jan-04 22:28
mylitziname12-Jan-04 22:28 
GeneralRe: axwebbrowser excel mdicontainer Pin
mylitziname12-Jan-04 23:24
mylitziname12-Jan-04 23:24 
GeneralEnvironment variable Pin
cfl12-Jan-04 22:03
cfl12-Jan-04 22:03 
GeneralRe: Environment variable Pin
mylitziname12-Jan-04 23:33
mylitziname12-Jan-04 23:33 
GeneralRe: Environment variable Pin
Heath Stewart13-Jan-04 5:15
protectorHeath Stewart13-Jan-04 5:15 
GeneralRe: Environment variable Pin
cfl13-Jan-04 15:42
cfl13-Jan-04 15:42 
General.NET version dependent compilation Pin
brain2cpu12-Jan-04 21:09
professionalbrain2cpu12-Jan-04 21:09 
GeneralRe: .NET version dependent compilation Pin
Heath Stewart13-Jan-04 5:12
protectorHeath Stewart13-Jan-04 5:12 
QuestionDragDrop to a native window? Pin
TuringTest112-Jan-04 19:20
TuringTest112-Jan-04 19:20 
AnswerRe: DragDrop to a native window? Pin
Heath Stewart13-Jan-04 5:07
protectorHeath Stewart13-Jan-04 5:07 
GeneralRe: DragDrop to a native window? Pin
TuringTest113-Jan-04 5:55
TuringTest113-Jan-04 5:55 
Generalasking for system tray application Pin
azusakt12-Jan-04 16:25
azusakt12-Jan-04 16:25 
GeneralRe: asking for system tray application Pin
Jeff Mackie12-Jan-04 17:16
sussJeff Mackie12-Jan-04 17:16 
GeneralRe: asking for system tray application Pin
azusakt12-Jan-04 17:51
azusakt12-Jan-04 17:51 
GeneralRe: asking for system tray application Pin
Heath Stewart13-Jan-04 4:53
protectorHeath Stewart13-Jan-04 4:53 
Questionreturning when inside a lock - is it safe? Pin
Brandon Haase12-Jan-04 15:29
Brandon Haase12-Jan-04 15:29 
AnswerRe: returning when inside a lock - is it safe? Pin
Heath Stewart13-Jan-04 4:46
protectorHeath Stewart13-Jan-04 4:46 
GeneralRe: returning when inside a lock - is it safe? Pin
Brandon Haase13-Jan-04 16:13
Brandon Haase13-Jan-04 16:13 
AnswerRe: returning when inside a lock - is it safe? Pin
scadaguy13-Jan-04 5:23
scadaguy13-Jan-04 5:23 
Brandon,

Returning inside a lock is okay.

I don't necessarily see anything incorrect about your implementation. However, the double-checked locking pattern is essentially useless as you have used it since you'll always be aquiring at least one lock anyway. I would suggest the following code...

public class IsoCurrencyInfo
{
    private static Hashtable _iciRegistry = new Hashtable();

    public static IsoCurrencyInfo GetInstance(string isoCode)
    {
        if (!_iciRegistry.Contains(isoCode))
        {
            lock (syncRoot)
            {
                if (!_iciRegistry.Contains(isoCode))
                {
                    _iciRegistry.Add(isoCode, new IsoCurrencyInfo(isoCode));
                }
            }
        }
        return (IsoCurrencyInfo)_iciRegistry[isoCode];
    }
}


It is important to realize that the Hashtable is the only IDictionary collection that will work as I have used it. This is because the Hashtable can support multiple readers and one writer simultaneously. Likewise, you won't be able to use the same trick with an ArrayList. In this implementation the lock is rarely acquired.

Brian
GeneralRe: returning when inside a lock - is it safe? Pin
Brandon Haase13-Jan-04 16:28
Brandon Haase13-Jan-04 16:28 

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.