B
Bob Altman
I'm trying to call a function on a background thread in a C++/CLI (VS 2005)
application compiled with /clr. I store a delegate reference in a module-level
gcroot. When I call BeginInvoke on the delegate I get a RemotingException. The
inner exception says "Pointer types cannot be passed in a remote call". A code
example that demonstrates the problem appears below.
Am I even wiring up the delegate/BeginInvoke/EndInvoke stuff correctly? The
documentation is pretty sketchy.
TIA - Bob
----- Code example -----
#include <gcroot.h>
using namespace System;
// Class with no members
class MyClass {
};
// Forward references
void BackgroundWorker(MyClass& myClass);
void _Callback(IAsyncResult ^ar);
// Module-level data
delegate void BackgroundWorkerDelegType(MyClass& myClass);
static gcroot<BackgroundWorkerDelegType^>
m_BackgroundWorkerDeleg
= gcnew BackgroundWorkerDelegType(&BackgroundWorker);
static gcroot<AsyncCallback^>
m_callbackDeleg
= gcnew AsyncCallback(&_Callback);
// Main program
int main(array<System::String ^> ^args)
{
MyClass myClass;
// RemotingException: Pointer types cannot be passed in a remote call
m_BackgroundWorkerDeleg->BeginInvoke(myClass, m_callbackDeleg, nullptr);
return 0;
}
void BackgroundWorker(MyClass& myClass)
{
Console::WriteLine("In BackgroundWorker");
}
// Routine called when the asynchronous call completes
void _Callback(IAsyncResult ^ar)
{
m_BackgroundWorkerDeleg->EndInvoke(ar);
}
application compiled with /clr. I store a delegate reference in a module-level
gcroot. When I call BeginInvoke on the delegate I get a RemotingException. The
inner exception says "Pointer types cannot be passed in a remote call". A code
example that demonstrates the problem appears below.
Am I even wiring up the delegate/BeginInvoke/EndInvoke stuff correctly? The
documentation is pretty sketchy.
TIA - Bob
----- Code example -----
#include <gcroot.h>
using namespace System;
// Class with no members
class MyClass {
};
// Forward references
void BackgroundWorker(MyClass& myClass);
void _Callback(IAsyncResult ^ar);
// Module-level data
delegate void BackgroundWorkerDelegType(MyClass& myClass);
static gcroot<BackgroundWorkerDelegType^>
m_BackgroundWorkerDeleg
= gcnew BackgroundWorkerDelegType(&BackgroundWorker);
static gcroot<AsyncCallback^>
m_callbackDeleg
= gcnew AsyncCallback(&_Callback);
// Main program
int main(array<System::String ^> ^args)
{
MyClass myClass;
// RemotingException: Pointer types cannot be passed in a remote call
m_BackgroundWorkerDeleg->BeginInvoke(myClass, m_callbackDeleg, nullptr);
return 0;
}
void BackgroundWorker(MyClass& myClass)
{
Console::WriteLine("In BackgroundWorker");
}
// Routine called when the asynchronous call completes
void _Callback(IAsyncResult ^ar)
{
m_BackgroundWorkerDeleg->EndInvoke(ar);
}