Click to See Complete Forum and Search --> : Multithreading and managed code


Shambler
May 9th, 2006, 12:39 PM
Here is a stripped down version of the code I have:
void QueryThreadProc(void* QueryRef)
{
// I want to call UT2k4MasterQuery::Tick here
}

UT2k4MasterQuery::UT2k4MasterQuery(char* Key, char* IP, int Port)
{
_beginthread(QueryThreadProc, 0, NULL);
}

void UT2k4MasterQuery::Tick()
{
}
Now, UT2k4MasterQuery is a managed C++ class and I want to find a way of calling UT2k4MasterQuery::Tick from QueryThreadProc.

I've tried passing function references/delegates as arguments for beginthread, using global references (which seem to be totally gone with managed C++??!!!) but without success.

This is really frustrating....what I'm trying to do SHOULD be incredibly simple and I've spent hours at it both searching and testing code, does anyone know how I can get it done?


Thanks.

Shambler
May 9th, 2006, 02:03 PM
Nevermind, I figured it out.

For anyone who is having the same problem, check this page:
http://www.codeproject.com/managedcpp/managedthreads.asp

The working code is:

UT2k4MasterQuery::UT2k4MasterQuery(char* Key, char* IP, int Port)
{
ThreadStart* tsNewThread = new ThreadStart(this, &UT2k4MasterQuery::Tick);
Thread* tNewThread = new Thread(tsNewThread);
tNewThread->Start();
}

void UT2k4MasterQuery::Tick()
{
}