I am trying to understand why this program is not working
Expected result: numbers 0-19 in random order What I get when I run: some numbers repeat, sometimes 20 is printed.
Please, help. I tried with lock (obj) in DoSomething (), but that didn't help.
Program
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace ConsoleApplication2 { public delegate void callbackDelegate(int x); class Program { void processCallback(int x) { Console.WriteLine("IN callback: The value I got is " + x); } static void Main(string[] args) { Program p = new Program(); p.processinThreads(); Console.ReadKey(); } public void DoSomething(int x, callbackDelegate callback) { Thread.Sleep(1000);
satya source share