consider for your case. Just adopt one of the simpler patterns that will
"Rick" <Rick@discussions.microsoft.com> wrote in message
news:D525DE04-72F7-452D-A126-295196D2C5F6@microsoft.com...
> Leon,
>
> Thanks for the response....Unfortunately with everything i've read (the
> links you've provided and other links) it seems as though the Double-Check
> Lock is not a recommended pattern (yes MSDN has recommended it, but i've
> read
> a bunch of other material which seem to think it's crazy that MSDN
> recommended that approach.
>
> Are there any other possible ways to accomplish what i've set out to do?
>
> Thanks,
>
> -Rick
>
> "Leon Welicki" wrote:
>
>> Hi Rick,
>>
>> You can use a Singleton combined with the Double-Check Lock idiom. This
>> way
>> you can ensure that only one instance of the Singleton exists.
>>
>> Then, you can serialize the access to the method of singleton object that
>> issues the check number using the lock sentence (or Monitor). This way,
>> you
>> won´t give the same number to differente callers (all invocations will be
>> serialized).
>>
>> Here are some pointers that may be of help:
>>
>> "Lock Statement and Thread Synchronization (C# Programmers Reference)"
>>
http://msdn2.microsoft.com/library/ms173179(en-us,vs.80).aspx
>>
>> "The Monitor Class"
>>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingmonitorclasstopic.asp
>>
>> "A Special Dr. GUI: Don´t Lock on Type Objects"
>>
http://msdn.microsoft.com/library/default.asp?url=/archive/en-us/dnaraskdr/html/askgui06032003.asp
>>
>> "Implementing the Singleton Pattern in C#"
>>
http://www.yoda.arachsys.com/csharp/singleton.html
>>
>> "Implementing the Singleton Pattern in C#"
>>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpatterns/html/DesSingleton.asp
>>
>> "Is the C# lock statement FIFO? (first come first serve)"
>>
http://www.dotnet247.com/247reference/msgs/49/246350.aspx >>
>> "Safe Thread Synchronization"
>>
http://msdn.microsoft.com/msdnmag/issues/03/01/NET/ >>
>> "The "Double-Checked Locking is Broken" Declaration"
>>
http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
>>
>> Hope this helps,
>>
>> Regards,
>> Leon Welicki
>>
>> "Rick" wrote:
>>
>> > I'm currently developing a distribution .Net Applicaiton utilizing .Net
>> > Remoting for client to server side communication (server side is where
>> > all
>> > business rules and workflow is created and controlled). The server
>> > side
>> > remoting objects which the clients proxy to are just workflow objects
>> > that
>> > then interact with a biz tier. I'm expecting anywhere from 1 to "n"
>> > number
>> > of clients utilizing the same server side components for their
>> > processing
>> > needs (server side engines all hit the same db).
>> >
>> > I'm faced with a situation where i need to increment a counter (of
>> > sorts) on
>> > my server side but this needs to follow a "singleton" like pattern.
>> > The
>> > application is financial and I need to make sure I do NOT issue
>> > duplicate
>> > Check Numbers for a given bank account when i'm producing a check
>> > document
>> > (obviously this is a big no-no). On initialization of the bank account
>> > (before i begin to even think about writing checks off of it), I have
>> > the
>> > next check number to use (again though, in a real life scenario I could
>> > have
>> > two clients who both initialize their own instance of that bank account
>> > object and then try to write checks off of that account).
>> >
>> > I can't utilize a traditional singleton object since I could have "n"
>> > clients all trying to write a check off of the same bank account at the
>> > same
>> > time. I'm fearing letting the DB handle the check numbering when i
>> > persist
>> > the check documents. I'm now searching for other aveneues to implement
>> > this
>> > singleton like pattern. Some things i've thought about:
>> >
>> > 1. COM+ Singleton Object (JIT activate, min and max pool size = 1).
>> > On
>> > instantiation, I create a hash table to house the bank account id and
>> > next
>> > check number to use. I then can query the object and if that bank
>> > account id
>> > exists in the hash table, return back the next check number. If it
>> > doesn't,
>> > add the bank account id to the hash table and then update the next
>> > number to
>> > use.
>> > 2. .Net Caching -- doesn't seem like a great implementation, but could
>> > somehow rig this to work
>> > 3. DB Handles Numbering when the check document is persisted --
>> > performance
>> > implications of this?
>> > 4. ???
>> > 5. ???
>> >
>> > If you have any ideas or suggestions, please let me know.
>> >
>> > Thanks,
>> >
>> > -Rick
>> >