473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Auto mutex "all" methods

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
Nov 21 '05 #1
2 996
Hi,

Take a look at the synclock statement.
http://msdn.microsoft.com/library/de...tmsynclock.asp

Ken
-----------------

"Tim" wrote:
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

Nov 21 '05 #2
Tim
Ken Tucker [MVP] wrote:
"Tim" wrote:
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)?
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
Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
4
by: Alex Sedow | last post by:
Method invocation will consist of the following steps: 1. Member lookup (14.3) - evaluate method group set (Base.f() and Derived.f()) .Standart say: "The compile-time processing of a method...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.