mirror of
https://github.com/Relintai/programming_tutorials.git
synced 2025-05-11 22:52:11 +02:00
39 lines
637 B
C#
39 lines
637 B
C#
using System;
|
|
using System.Threading;
|
|
|
|
class Program
|
|
{
|
|
private static Mutex mut = new Mutex();
|
|
|
|
static void ThreadFunc() {
|
|
if (mut.WaitOne()) {
|
|
|
|
mut.ReleaseMutex();
|
|
}
|
|
|
|
if (mut.WaitOne(1000)) {
|
|
//megkaptuk
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
mut.ReleaseMutex();
|
|
} else {
|
|
//timeout
|
|
}
|
|
}
|
|
|
|
~Program() {
|
|
//nem ajánlott a destruktor c#ban, mert nem garantált, hogy le fog futni
|
|
//mut.Dispose();
|
|
}
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
Console.WriteLine("Hello World!");
|
|
|
|
mut.Dispose();
|
|
}
|
|
|
|
|
|
}
|