kzsigo
asked on
Problem with compiling ThreadPools, multiple threads.
This question is prob. extremely trivial but I can't seem to find out
what is going on. I've been doing some basic work with Multithreading
and Worker Threads and have determined I'd like to set up a minor
project that has ThreadingPools.
I can't seem to get it to compile whether I follow the example
tutorials or I don't. Of course the latter has a higher percentage of
failing :)
Anyways the line that fails is:
ThreadPool::QueueUserWorkI tem(gcnew
System::Threading::WaitCal lback(t->T hreadCallB ack),i);
The examples don't show anything being passed into the function but
it's a bit necessary for me to have each of the threads know what
numbers they are. So I'd really like to send in the number they are.
The function I'm sending them to is:
void dthread::ThreadCallBack(Ob ject^ threadContext){
..
...
..
}
Now the errors I get all have to do with delegation of functions or
with pointers. I assumed that with this being a managed project I
didn't have to deal with most of that.
Errors:
Error 1 error C3867: 'dthread::ThreadCallBack': function call missing
argument list; use '&dthread::ThreadCallBack' to create a pointer to
member
Error 2 error C3350: 'System::Threading::WaitCa llback' : a delegate
constructor expects 2 argument(s)
Before you go about telling me that I shouldn't be using -> to point to
the function in the class allow me to tell you that my function is
*not* static. Furthermore I have instantiated the class before hand.
I"ve been following two tutorials from msdn, one does it, the other
doesn't.
Ie:
for (int i = 0; i........; i++){
MRE[i] = gcnew ManualResetEvent(false);
dthread^ t = gcnew dthread(this->clb_List->It ems[a]->To String(), MRE[i]);
WTHREAD[i] = t;
System::UInt32^ m_i = gcnew UInt32(i);
ThreadPool::QueueUserWorkI tem(gcnew System::Threading::WaitCal lback(t->T hreadCallB ack),i);
}
Now I can make one of them go away by removing the parameter or even moving the parameter into the WaitCallback but I dont think that's right. Can anyone point me into the right direction.
TIA.
what is going on. I've been doing some basic work with Multithreading
and Worker Threads and have determined I'd like to set up a minor
project that has ThreadingPools.
I can't seem to get it to compile whether I follow the example
tutorials or I don't. Of course the latter has a higher percentage of
failing :)
Anyways the line that fails is:
ThreadPool::QueueUserWorkI
System::Threading::WaitCal
The examples don't show anything being passed into the function but
it's a bit necessary for me to have each of the threads know what
numbers they are. So I'd really like to send in the number they are.
The function I'm sending them to is:
void dthread::ThreadCallBack(Ob
..
...
..
}
Now the errors I get all have to do with delegation of functions or
with pointers. I assumed that with this being a managed project I
didn't have to deal with most of that.
Errors:
Error 1 error C3867: 'dthread::ThreadCallBack':
argument list; use '&dthread::ThreadCallBack'
member
Error 2 error C3350: 'System::Threading::WaitCa
constructor expects 2 argument(s)
Before you go about telling me that I shouldn't be using -> to point to
the function in the class allow me to tell you that my function is
*not* static. Furthermore I have instantiated the class before hand.
I"ve been following two tutorials from msdn, one does it, the other
doesn't.
Ie:
for (int i = 0; i........; i++){
MRE[i] = gcnew ManualResetEvent(false);
dthread^ t = gcnew dthread(this->clb_List->It
WTHREAD[i] = t;
System::UInt32^ m_i = gcnew UInt32(i);
ThreadPool::QueueUserWorkI
}
Now I can make one of them go away by removing the parameter or even moving the parameter into the WaitCallback but I dont think that's right. Can anyone point me into the right direction.
TIA.
ASKER
Unfortunately that brings me to a Link error.
Do I need to include a class prototype?
LNK2020 : unresolved token (06000000E) CU.Form1::ThreadCallBack
TIA.
Do I need to include a class prototype?
LNK2020 : unresolved token (06000000E) CU.Form1::ThreadCallBack
TIA.
What is the class where ThreadCallBack function is defined? Please post enough information.
ASKER
The class that I'm developing is:
"dthread".
Form1::bn_start_Click is where:
for (int i = 0; i........; i++){
MRE[i] = gcnew ManualResetEvent(false);
dthread^ t = gcnew dthread(this->clb_List->It ems[a]->To String(), MRE[i]);
WTHREAD[i] = t;
System::UInt32^ m_i = gcnew UInt32(i);
ThreadPool::QueueUserWorkI tem(gcnew System::Threading::WaitCal lback(t->T hreadCallB ack),i);
}
is defined.
dthread is in a separate file.
With the function being defined inside the dthread.cpp.
The class has a couple functions with the ThreadCallBack being the function that I'd like executed.
Inside another class, Form1, is where I'm creating 5 threads. Each thread is one instantiation of dthread.
I guess, in specific, I have Void Form1::bn_start_Click(Obje ct^ sender, System::EventArgs^ e) which creates the five . This function is actually defined in the Form1.h
Would you like me to post more information about the class itself? Like the code of the class?
"dthread".
Form1::bn_start_Click is where:
for (int i = 0; i........; i++){
MRE[i] = gcnew ManualResetEvent(false);
dthread^ t = gcnew dthread(this->clb_List->It
WTHREAD[i] = t;
System::UInt32^ m_i = gcnew UInt32(i);
ThreadPool::QueueUserWorkI
}
is defined.
dthread is in a separate file.
With the function being defined inside the dthread.cpp.
The class has a couple functions with the ThreadCallBack being the function that I'd like executed.
Inside another class, Form1, is where I'm creating 5 threads. Each thread is one instantiation of dthread.
I guess, in specific, I have Void Form1::bn_start_Click(Obje
Would you like me to post more information about the class itself? Like the code of the class?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ThreadPool::QueueUserWorkI