G
Guest
Greetings,
I am trying to fire aysnc events in c++/clr, and I can't seem to get it to
work.
It seems to work fine in c#, but when I try c++/clr, I can't seem to get it
to compile in the c++/clr class.
I.) Event Testing in C#, which works fine:
public class CSharpEventTest
{
public event CSharpDelegate AsyncEvent = null;
public event CSharpDelegate SyncEvent = null;
public void FireAsyncEvent(string message)
{
if (AsyncEvent == null) return;
AsyncEvent.BeginInvoke(message, null, this);
}
public void FireSyncEvent(string message)
{
if (SyncEvent == null) return;
SyncEvent(message);
}
}
II. Event Testing in MC++, which doesn't compile correctly.
public delegate bool MCDelegate(System::String^ errorCode);
public ref class MCEventTesting
{
public:
MCEventTesting(void);
event MCDelegate^ EventSync;
event MCDelegate^ EventASync;
public:
void FireEventAsync(System::String^ errorCode)
{
// Doesn't compile, gives an error:
//"invalid argument for delegate constructor; delegate target needs to be a
// pointer to a member function"
MyErrorDelegate^ delg = gcnew MyErrorDelegate(EventASync(errorCode));
delg.BeginInvoke(NULL, delg);
}
// Works fine
void FireEventSync(System::String^ errorCode)
{
EventSync(errorCode);
}
};
Thanks for any suggestions!
I am trying to fire aysnc events in c++/clr, and I can't seem to get it to
work.
It seems to work fine in c#, but when I try c++/clr, I can't seem to get it
to compile in the c++/clr class.
I.) Event Testing in C#, which works fine:
public class CSharpEventTest
{
public event CSharpDelegate AsyncEvent = null;
public event CSharpDelegate SyncEvent = null;
public void FireAsyncEvent(string message)
{
if (AsyncEvent == null) return;
AsyncEvent.BeginInvoke(message, null, this);
}
public void FireSyncEvent(string message)
{
if (SyncEvent == null) return;
SyncEvent(message);
}
}
II. Event Testing in MC++, which doesn't compile correctly.
public delegate bool MCDelegate(System::String^ errorCode);
public ref class MCEventTesting
{
public:
MCEventTesting(void);
event MCDelegate^ EventSync;
event MCDelegate^ EventASync;
public:
void FireEventAsync(System::String^ errorCode)
{
// Doesn't compile, gives an error:
//"invalid argument for delegate constructor; delegate target needs to be a
// pointer to a member function"
MyErrorDelegate^ delg = gcnew MyErrorDelegate(EventASync(errorCode));
delg.BeginInvoke(NULL, delg);
}
// Works fine
void FireEventSync(System::String^ errorCode)
{
EventSync(errorCode);
}
};
Thanks for any suggestions!