Scrigroup - Documente si articole

Username / Parola inexistente      

Home Documente Upload Resurse Alte limbi doc  


AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows
WordXml

AspAutocadCDot netExcelFox proHtmlJava
LinuxMathcadPhotoshopPhpSqlVisual studioWindowsXml

The lock Statement

c

+ Font mai mare | - Font mai mic



DOCUMENTE SIMILARE

Trimite pe Messenger
Sequence points
Control Flow: Statements and Blocks
The Wait() and Pulse() Mechanism
Arrays, the & operator and function
Multiple Threads in Applications - STA Threading Model
Declarations, Definitions and Accessibility - Storage class specifiers
The lock Statement
Statements: Selection Statements
Preprocessor statements
Defining Threads - Single-Threaded Processes


The lock Statement

The lock keyword can be used as an alternative to the methods of the Monitor class. The following two blocks of code are equivalent:




Monitor.Enter(x)

Monitor.Exit(x)

lock(this)

The following example, Locking.cs, uses the lock keyword instead of the explicit Monitor methods:

using System;
using System.Threading;

namespace Lock


Console.WriteLine('Exiting Thread ' +
Thread.CurrentThread.GetHashCode());



public static void Main()



The output from Locking.cs will be the same as for MonitorEnterExit (when a parameter has been supplied):

Entered Thread 2
Result = 0 ThreadID 2
Result = 1 ThreadID 2
Result = 2 ThreadID 2
Result = 3 ThreadID 2
Result = 4 ThreadID 2
Exiting Thread 2
Entered Thread 3
Result = 5 ThreadID 3
Result = 6 ThreadID 3
Result = 7 ThreadID 3
Result = 8 ThreadID 3
Result = 9 ThreadID 3
Exiting Thread 3





Politica de confidentialitate



DISTRIBUIE DOCUMENTUL

Comentarii


Vizualizari: 364
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2022 . All rights reserved

Distribuie URL

Adauga cod HTML in site