/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/fundamentals/runtime-libraries/snippets/System.Threading/Monitor/Overview/csharp/Pattern2.cs
34 строки
681 B
Genevieve Warren
Add remarks for core types (#38970)
05 янв 2024, 22:14
Не верифицирован
05 янв 2024, 22:14
71d1377
Код
Авторство
О чём код?
using System; using System.Runtime.CompilerServices; using System.Threading; public class Example3 { public static void Main() { // <Snippet2> // Define the lock object. var obj = new Object(); // Define the critical section. Monitor.Enter(obj); try { // Code to execute one thread at a time. } // catch blocks go here. finally { Monitor.Exit(obj); } // </Snippet2> } // <Snippet3> [MethodImplAttribute(MethodImplOptions.Synchronized)] void MethodToLock() { // Method implementation. } // </Snippet3> }