Sync Delegate : synchronized « Thread « C# / CSharp Tutorial






using System.Threading;
using System;

  public delegate int BinaryOp(int x, int y);

  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Main() invoked on thread {0}.",Thread.CurrentThread.ManagedThreadId);
      BinaryOp b = new BinaryOp(Add);
      int answer = b(10, 10);
      Console.WriteLine("Doing more work in Main()!");
      Console.WriteLine("10 + 10 is {0}.", answer);
      Console.ReadLine();
    }
    static int Add(int x, int y)
    {
      Console.WriteLine("Add() invoked on thread {0}.",Thread.CurrentThread.ManagedThreadId);
      Thread.Sleep(5000);
      return x + y;
    }
  }








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