I'm confused with using and not using Invoke.
In the following example, I see no difference with
int answer = b(10, 10);
and
int answer = b.Invoke(10, 10);
so can anyone help me with this? thx!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace TEST
{
public delegate int BinaryOp(int x, int y);
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Main innvoked on thread {0}.", Thread.CurrentThread.ManagedThreadId);
BinaryOp b = new BinaryOp(add);
//int answer = b(10, 10);
int answer = b.Invoke(10, 10);
Console.WriteLine("Doing more work in Main");
Console.WriteLine("10 + 10 is {0}", answer);
Console.Read();
}
static int add(int x, int y)
{
Console.WriteLine("add innvoked on thread {0}.", Thread.CurrentThread.ManagedThreadId);
return x + y;
}
}
}