Auto mutex "all" methods

T

Tim

We have a legacy VB .NET class that relies on quite a few gloabal
variables and states. It handles calls from different threads well as
long as two calls doesn't come at the same time so a viable solution
would be to enclose all the public methods in a construct like this

Monitor.Enter(me.globaLock)
try
<func tionbody>
finally
Monitor.exit(me.globalLock)
end try

This is not an ugly, errorprone solution that causes a lot of work so
instead I would like to know if it is possible to automatically force
the object to allow only one thread to use it at any given moment and
force other calling threads to wait (as would happen with a monmitor in
each public method)?

Many thanks

Tim
 
T

Tim

Take a look at the synclock statement.

Thanks for the pointer, it is definitley a much better solution in terms
of simplicity but it is still just syntactic suggar for an ordinary
monitor construct.

For me it would be better to mark the class (or the object upon
creation) as "let only one thread use me at the time". But I guess that
is not possible then.

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top