Public · Protected · Private
Threading in C#
Type: Public  |  Created: 2008-08-24  |  Frozen: Yes
« Previous Public Blog Next Public Blog »
Comments
  • //Add a delegate public delegate int binaryop(int a, int b); private int add(int a, int b) { Thread.Sleep(5000); MessageBox.Show("a Done"); return a + b; } private void addDone(IAsyncResult rr) { MessageBox.Show("ADDDONE"); } Now try main() { binaryop b = new binaryop(add); int X = b(10, 10); IAsyncResult res = b.BeginInvoke(10, 10, null, null); MessageBox.Show("m Done"); int Y = b.EndInvoke(res); IAsyncResult res2 = b.BeginInvoke(10, 10, addDone, null); MessageBox.Show("m Done"); int Z = b.EndInvoke(res2); }
    2008-08-24 02:25
  • Other ways of starting threads is Thread r = new Thread( new ParameterizedThreadStart(iteratenumbers)); r.Start(10000 ); Thread s = new Thread(new ParameterizedThreadStart(iteratenumbers)); s.Start(100000); Where int globalI = 0; private void iteratenumbers(object r) { Monitor.Enter(this); int x = (Int32)r;int z = 0; for (; globalI < x; globalI++) { lock (this) { z++; } } MessageBox.Show(z.ToString()); Monitor.Exit(this); }
    2008-08-24 02:27
  • Thread synchronization in next topic....
    2008-08-24 02:29
This blog is frozen. No new comments or edits allowed.