Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Synchronized in VB? (Threads)

Status
Not open for further replies.

Raste

Programmer
Jul 21, 2002
7
DK
Hi.

Is there any way to protect a method in a threading evnironment, so that only one thread gets to call the function at a time (like the synchronized attribute in java)?
 
Hello Raste,
I have never tried to create a multithreaded application in VB.net so what you will read here is out of the MSDN.

Synchronization [Visual Basic]

"Synchronization is a logical thread of execution, sometimes called an activity. COM+ provides synchronization that flows from object to object and prohibits more than one caller from entering the component at any given time. Synchronization determines when threads can dispatch calls to an object.

To use automatic synchronization, apply the SynchronizationAttribute attribute to a class that derives from System.EnterpriseServices.ServicedComponent.

If the caller is configured to support or require automatic transactions, the value of the SynchronizationOption enumeration is automatically set to Required. If the caller is configured to require a new transaction, the enumeration is set to RequiresNew.

The following example shows how to enable synchronization on instances of the TestSync class:


Code:
[Visual Basic]
<Synchronization()> _
Public Class TestSync 
Inherits ServicedComponent
&quot;

I hope that this helps.

MSDN link:ms-help://MS.VSCC/MS.MSDNQTR.2002APR.1033/cpguide/html/cpconsynchronizationactivity.htm &quot;The Camel will walk the desert of programming once again ...&quot;

Camel
 
Well, it did help me because when i tried to search for the <Synchronization()> attribute, i found the Monitor object which has the following methods

Monitor.Enter(Object)
..do stuff with Object.
Monitor.Exit(Object)

, and it worked very well, so thanks for the hint :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top