Scrigroup - Documente si articole

     

HomeDocumenteUploadResurseAlte 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



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 | Termeni si conditii de utilizare



DISTRIBUIE DOCUMENTUL

Comentarii


Vizualizari: 692
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 2024 . All rights reserved