Using synchronized methods : synchronized « Thread « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime;
using System.Runtime.CompilerServices;
using System.Security;
using System.Text;
using System.Threading;

public class MainClass
{
    private static int count = 0;
    private static object myMutex = new object();
    
    [MethodImpl(MethodImplOptions.Synchronized)]
    public static void Main()
    {
         count++;

    }
}








20.16.synchronized
20.16.1.Using synchronized methods
20.16.2.Sync Delegate
20.16.3.Shared Resource
20.16.4.Synchronous Writing, Asynchronous Reading