Click here to Skip to main content
15,923,789 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
QuestionChecking For Null while rasing the events Pin
Sangeetha.R30-Mar-06 0:03
Sangeetha.R30-Mar-06 0:03 
AnswerRe: Checking For Null while rasing the events Pin
Milton Karimbekallil30-Mar-06 4:08
Milton Karimbekallil30-Mar-06 4:08 
GeneralRe: Checking For Null while rasing the events Pin
Sangeetha.R30-Mar-06 21:18
Sangeetha.R30-Mar-06 21:18 
GeneralRe: Checking For Null while rasing the events Pin
Milton Karimbekallil31-Mar-06 1:54
Milton Karimbekallil31-Mar-06 1:54 
AnswerRe: Checking For Null while rasing the events Pin
2bee 31-Mar-06 3:17
2bee 31-Mar-06 3:17 
GeneralRe: Checking For Null while rasing the events Pin
Sangeetha.R2-Apr-06 18:44
Sangeetha.R2-Apr-06 18:44 
GeneralRe: Checking For Null while rasing the events Pin
2bee 2-Apr-06 20:13
2bee 2-Apr-06 20:13 
AnswerRe: Checking For Null...a different approach Pin
2bee 4-Apr-06 0:58
2bee 4-Apr-06 0:58 
Hi,

immediately after telling you to use a delegate i found myself confronted with a similar problem.
Though i had to find a solution for myself as well. Basically in my case, i need to check a remote event for any dead delegates which are still connected to it. Otherwise it will end up in a remoting exception each time i'll raise the event. So i did the following:

public delegate void SensorUpdatedEventHandler (Object^, UpdateEventArgs^);
 
public ref class SensorWebLink : ...
{
  ...
 
  SensorWeblink()
  {
    _RemotelyInvokedDelegates = nullptr;
  }
 
  ...
  ...
 
  private:
 
   static  SensorUpdatedEventHandler^  _RemotelyInvokedDelegates;
  
  public:		
		
    event SensorUpdatedEventHandler^  SensorUpdatedEvent
    {		
      void add(SensorUpdatedEventHandler^ pDelegate) 
      {
        _RemotelyInvokedDelegates += pDelegate;
      }
 
     void remove(SensorUpdatedEventHandler^ pDelegate) 
     {
       _RemotelyInvokedDelegates -= pDelegate;
     }
 
     void raise(Object^ pObject, UpdateEventArgs^ pEvtArgs) 
     {
       if (_RemotelyInvokedDelegates) 
       {
         _RemotelyInvokedDelegates->Invoke(pObject, pEvtArgs);
       }
     }
   };
 
   void RaiseSensorUpdatedEvent (UpdateEventArgs^ pEvtArgs);
};
  
// now i can easily access the invocation list
  
void SensorWebLink::RaiseSensorUpdatedEvent(UpdateEventArgs^ pEvtArgs)
{
  if(_RemotelyInvokedDelegates == nullptr)
  {
    Console::WriteLine("No listeners");
  }
  else
  {
    Console::WriteLine("Number of Listeners: {0}",_RemotelyInvokedDelegates->GetInvocationList()->Length);
    SensorUpdatedEventHandler^ temporaryHandler = nullptr; 
     
    for each( Delegate^ del in _RemotelyInvokedDelegates->GetInvocationList())
    {
       try
       {
         temporaryHandler = (SensorUpdatedEventHandler^) del;
         temporaryHandler(this, pEvtArgs);
       }
       catch( Exception^ e )
       {
         Console::WriteLine( e->ToString() );
         _RemotelyInvokedDelegates -= temporaryHandler;
       }
    }
  }
}
Btw. I had this idea after reading this msdn article:

http://msdn2.microsoft.com/en-US/library/5f3csfsa(VS.80).aspx[^]

cheers Tobias
GeneralUniscribe woes... Pin
Super Lloyd29-Mar-06 13:05
Super Lloyd29-Mar-06 13:05 
GeneralRe: Uniscribe woes... Pin
George L. Jackson29-Mar-06 17:49
George L. Jackson29-Mar-06 17:49 
GeneralRe: Uniscribe woes... Pin
Super Lloyd29-Mar-06 17:57
Super Lloyd29-Mar-06 17:57 
QuestionSystem::DateTime HELP Please Pin
Saber00129-Mar-06 2:25
Saber00129-Mar-06 2:25 
AnswerRe: System::DateTime HELP Please Pin
2bee 29-Mar-06 11:19
2bee 29-Mar-06 11:19 
GeneralRe: System::DateTime HELP Please Pin
Saber00130-Mar-06 2:31
Saber00130-Mar-06 2:31 
AnswerRe: System::DateTime HELP Please Pin
George L. Jackson29-Mar-06 17:15
George L. Jackson29-Mar-06 17:15 
QuestionAbout delete in Managed C++ Pin
Bob_Sun28-Mar-06 18:34
Bob_Sun28-Mar-06 18:34 
AnswerRe: About delete in Managed C++ Pin
George L. Jackson29-Mar-06 17:21
George L. Jackson29-Mar-06 17:21 
QuestionSimple question about header files Pin
Virtek27-Mar-06 8:49
Virtek27-Mar-06 8:49 
AnswerCorrection Pin
Virtek27-Mar-06 8:51
Virtek27-Mar-06 8:51 
GeneralRe: Correction Pin
mcljava27-Mar-06 9:58
mcljava27-Mar-06 9:58 
AnswerRe: Simple question about header files Pin
2bee 27-Mar-06 9:48
2bee 27-Mar-06 9:48 
AnswerRe: Simple question about header files Pin
Divyang Mithaiwala28-Mar-06 21:25
Divyang Mithaiwala28-Mar-06 21:25 
GeneralRe: Simple question about header files Pin
Saksida Bojan29-Mar-06 9:48
Saksida Bojan29-Mar-06 9:48 
QuestionProblem in converting Unmanaged C++ Code to Managed C++ Code Pin
sunil440026-Mar-06 18:33
sunil440026-Mar-06 18:33 
AnswerRe: Problem in converting Unmanaged C++ Code to Managed C++ Code Pin
2bee 26-Mar-06 20:40
2bee 26-Mar-06 20:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.