M
Mike
I would like to pass an Object* to a delegated thread function.
However, the framework does not accommodate this. I have seen examples
using VB and even C#. In fact, C# appears to have language facilities
that make accomplishing this very easy. However, I only have the
luxury of coding this up in C++. So far the closest I've been able to
come to facilitating this is something like the following.
typedef void (*DelegateFunc)(Object __gc *);
__gc class ThreadClosure
{
private:
static Object* c_pArgs;
static DelegateFunc c_pfDelegate;
public:
ThreadClosure(
DelegateFunc pfDelegate,
Object* pArgs)
{
c_pfDelegate = pfDelegate;
c_pArgs = pArgs;
}
virtual ~ThreadClosure(void) {}
static void Run(void)
{
if (c_pfDelegate)
c_pfDelegate(c_pArgs)
}
};
The one flaw in the above scheme is the use of statis members. I have
no real guarantee between constructing an instance and initializing
the static closure and passing the run execution to the thread
delegate that the closure will remain what I set it to.
Ideally I'd like to pass a closure instance, or the Run method address
from that instance, to the thread delegate. Is this possible in the
C++ implementation of ThreadStart()?
Any tips would be massively appreciated!
Best regards,
Michael Powell
However, the framework does not accommodate this. I have seen examples
using VB and even C#. In fact, C# appears to have language facilities
that make accomplishing this very easy. However, I only have the
luxury of coding this up in C++. So far the closest I've been able to
come to facilitating this is something like the following.
typedef void (*DelegateFunc)(Object __gc *);
__gc class ThreadClosure
{
private:
static Object* c_pArgs;
static DelegateFunc c_pfDelegate;
public:
ThreadClosure(
DelegateFunc pfDelegate,
Object* pArgs)
{
c_pfDelegate = pfDelegate;
c_pArgs = pArgs;
}
virtual ~ThreadClosure(void) {}
static void Run(void)
{
if (c_pfDelegate)
c_pfDelegate(c_pArgs)
}
};
The one flaw in the above scheme is the use of statis members. I have
no real guarantee between constructing an instance and initializing
the static closure and passing the run execution to the thread
delegate that the closure will remain what I set it to.
Ideally I'd like to pass a closure instance, or the Run method address
from that instance, to the thread delegate. Is this possible in the
C++ implementation of ThreadStart()?
Any tips would be massively appreciated!
Best regards,
Michael Powell