Invoking delegates

P

Pavils Jurjans

Hello,

I am reading the article
http://msdn.microsoft.com/msdnmag/issues/04/01/BasicInstincts/ , and, since
the sample code is VB.NET, I am wondering what the heck is the "Invoke"
method :) I used to think that I can simply directly call the delegate
type instance with parameters:

public class Executer
{
public delegate bool TestDelegateType(string strValue);

static bool TestDelegateMethod(string strValue)
{
Console.WriteLine("TestDelegateMethod got value:" + strValue);
return strValue == "ABC";
}

static void Main( )
{
TestDelegateType TestDelegate = new TestDelegateType(TestDelegateMethod);
// Simple call
bool result = TestDelegate("ABC");
Console.WriteLine("Call to TestDelegate returned: " + result);
Console.ReadLine();
}

}

As far as I know, I can not do anything like TestDelegate.Invoke("ABC",
null, null) in C#? So, apparently there is some syntax issue in VB.NET
preventing the direct execution of delegate, and it has to do it via Invoke
method? Please, clear this up for me, so I can have better understanding of
samples where there is no C# code.

Taking it further, what is the simplest C# syntax of launching the given
delegate asynchorously?

Thanks,

Pavils
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top