Click to See Complete Forum and Search --> : Events and Delegates


lloydy
July 29th, 2004, 12:06 AM
Hi all,

I have established an event delegate class below:

public __gc class RxNotifier {

public:
//This is a singleton
private:RxNotifier(){}
private:static RxNotifier *ptr_to_RxNotifier;
public:static RxNotifier* MakeInstance()
{
if(ptr_to_RxNotifier == 0)
{
ptr_to_RxNotifier = new RxNotifier;
}
return ptr_to_RxNotifier;
}

// this is the delegate that does the events for us
__delegate void RxMsgHandler(System::Collections::ArrayList* msg);

// this is the event, of the delegate type
__event RxMsgHandler* RxMsg;

void Notify(System::Collections::ArrayList* msg) {
RxMsg(msg);
}
};
{

On one thread(2832), I then add a method as such:


_rxNotifier = RxNotifier::MakeInstance();
_rxNotifier->RxMsg += new RxNotifier::RxMsgHandler(this, DataComplete);
{

Then in another thread (2896) I fire the event:

_notifier = RxNotifier::MakeInstance();
_notifier->Notify(msg);
{

I then find that when I trace the code to the "DataComplete" method, which is the method I added to the handler, the thread that fired it is still running (2896).

My question is then.....how do I get the original thread(2832) to pick up the message, and allow the firing thread (2896) to continue.

Sorry for the long question. Thanks in advance

Lloydy

lloydy
July 30th, 2004, 01:13 AM
My apologies, Ive worked this out.

The delegate works as a type safe function pointer. I have started using BeginInvoke for threading purposes.

Cheers :wave: