Hi Gerry,
Yes, the solution Dave provided is a correct solution per your requirement.
Net provides the automatic synchronization for us through
System.Runtime.Remoting.Contexts.SynchronizationAttribute. However,
components must be context-bound to take advantage of .NET automatic
synchronization. We can simple use it like this:
using System.Runtime.Remoting.Contexts;
[Synchronization]
public class MyClass : ContextBoundObject
{
public MyClass(){}
public void DoSomething(){}
//other methods and data members
}
As you can see, it is very easy to use.
The reason that the component must derive from ContextBoundObject is that
ContextBoundObject tells .NET to place all the objects in a context
(synchronization domain) and associate them with a lock, so multiple
threads can't make concurrent calls within the same synchronization domain.
Additionally, we can choose the synchronization domain while applying
SynchronizationAttribute. That is we can choose whether to create a new
synchronization domain or share the same synchronization domain as the
caller. This is based on the value we passed to SynchronizationAttribute's
constructor:
REQUIRED or REQUIRES_NEW. Normally, REQUIRED is the default value and is
what you want. However, if your application uses Class Factories pattern to
create your new component, you may want to create a new synchronization
domain for your component (using REQUIRES_NEW).
Juval Lowy has written a good article covering this automatic
synchronization in .Net:
"Sync Threads Automatically"
http://www.ftponline.com/vsm/2002_09/magazine/columns/blackbelt/default_pf.a
spx
Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.