Problem with loosely coupled events

M

Mark Ritchie

I've been fighting with loosely coupled events for the last couple of days,
and currently have the following scenario:



Interface


namespace MyAssembly

{

public interface IMySink

{

void OnSyncEvent();

}



[EventClass]

public class MyEventClass : ServicedComponent,IMySink

{

public void OnSyncEvent ()

{

throw(new NotImplementedException(exception));

}

const string exception = @"You should not call an event class
directly. Register this assembly using RegSvcs /reconfig";

}

}





Message Class


public class MyMessage

{

public string Forename;

public string Surname;

}



Publisher


IMySink sink = new MyEventClass();

MyMessage myMessageObj = new MyMessage();

myMessageObj.Forename = "John";

myMessageObj.Surname = "Smith";



// Code for SerializeThis not included

string myMessageStr = SerializeThis(myMessageObj);

sink.OnSyncEvent(myMessageStr);





Subscriber


class SynchronisationSubscriberClass :ServicedComponent, IMySink

{

private MyWindowsFormClass formWindow;



public MyWindowsFormClass FormWindow

{

set {formWindow = value;}

}



public void OnSyncEvent (string message)

{

MyMessage myMessageObj = DeserializeThis(message);

formWindow.DoSomethingWithMessage(myMessageObj);

}

}





Problem


When the OnSyncEvent method is called in the subscriber the instance of
formWindow is null. I presume this is because the code is running in a COM+'
s memory space and not the memory space that the rest of the application
which instantiated the subscriber is running. If this is the case how do I
hook back into my main application? Hopefully somebody out there can help me
as Microsoft's help in this area is next to non-existent.
 
W

Willy Denoyette [MVP]

Not sure what you expect, FormWindow is a property of the
SynchronisationSubscriberClass class, but nowhere you set this property,
the only thing you do is fire an event at least in the snip of code you
posted.

Willy.
 

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

Top