Re: Interfaces and Events

Tech-Archive recommends: Fix windows errors by optimizing your registry



Bob Jones wrote:
Jon,

That's how I originally set the interface up. However, I found that I could not figure out how Program C was supposed to cosume those events. The events are raised by Class B and need to be consumed by Program C.

My understanding is that Class B need to implement the delegates and Program C should consume those events. How can I make this situation work?

Regards


<snip />

Not sure if this is what you are looking for:

namespace ConsoleApplication14
{
delegate void FooHandler();

interface IXox
{
event FooHandler Foo;
}

class Lulli : IXox
{
public event FooHandler Foo;

public void OnFoo()
{
if (Foo != null)
Foo();
}
}

class Program
{
static void Main(string[] args)
{
IXox xox = new Lulli();
xox.Foo += new FooHandler(xox_Foo);

// Demo: Raise the event!
((Lulli)xox).OnFoo();
}

static void xox_Foo()
{
Console.WriteLine("Foo called.");
}
}
}

Or do you mean the C is really another different programm? Then you have to do some sort of IPC, e.g. remoting.

HTH,
Andy

--
To email me directly, please remove the *NO*SPAM* parts below:
*NO*SPAM*xmen40@*NO*SPAM*gmx.net
.



Relevant Pages

  • Re: Interfaces and Events
    ... Program C should consume those events. ... class Lulli: IXox ... public event FooHandler Foo; ... static void Main ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: kgdb 2.0.5
    ... When using the ethernet interface, ... ++static int bufnum; ... ++static void kgdbeth_holdxlock ...
    (Linux-Kernel)
  • Re: C++ COM object calling C# delegate callback causes crash
    ... Where the delegate is passed in a different way. ... public interface IDVBSubtitle ... public static void SetFilter{ ... With this change it actually works, the callback is now called as ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Suggestion regarding reflexion and dynamic load of controls
    ... static void GetModules() ... foreach ... implemented into a dll? ... implement a specific interface, I need to be able to load that class ...
    (microsoft.public.dotnet.csharp.general)
  • Re: Declaring a Constructor in an Interface?
    ... > static void SpeedTestInterface ... > Somewhat interestingwas that the interface approach ... implementing IFoo. ... ABC: ...
    (microsoft.public.dotnet.languages.csharp)