-3

Here is my Main class code:

DelegateClass dc = new DelegateClass();
MyDelegate mydelegate = new MyDelegate(dc.WriteName);
ParameterLess paramless = new ParameterLess(dc.ShowName);
IAsyncResult mydelresult = mydelegate.BeginInvoke("Some Data",null,null);
var result = mydelegate.EndInvoke(mydelresult);
Console.WriteLine("Name is {0} ", result);

IAsyncResult myparamless = paramless.BeginInvoke(null,null);
result = paramless.EndInvoke(myparamless);
Console.WriteLine("Greeting is {0} ", result);
Console.WriteLine();
Console.ReadLine();

Here is my DelegateClass:

public string WriteName(string Name)
{
    return Name;      
}

public string ShowName()
{
    return "Hello";    
}

public string idea(string idea)
{
    return idea;
}

As the definition of idea and WriteName are same, I want to make them a multicast delegate by using BeginInvoke and EndInvoke.Can some one tell me how to do that.Is it possible?

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
Muhammad Ali
  • 853
  • 1
  • 10
  • 18
  • Please put more effort into formatting your code before posting. Just look at the preview before you post, and ask yourself whether that's how you'd like to see the code if you were answering the question. – Jon Skeet Sep 08 '14 at 14:56
  • Additionally, your question isn't really clear. You can create a multicast delegate just by using `Action action = dc.WriteName; action += dc.idea;` Where does the asynchrony come in? – Jon Skeet Sep 08 '14 at 14:57
  • 1
    There is no point whatsoever in immediately calling EndInvoke after calling BeginInvoke. Just Invoke directly, exact same outcome minus the cost of a tp thread. – Hans Passant Sep 08 '14 at 14:58

1 Answers1

-1

you can not use multicast delegate using asyn calling, because each asyn call executes on separate thread, and you have no option for second thread to execute.i-e the multicasted one.

Karim Musa
  • 378
  • 1
  • 2
  • 9