c++ threadpool.queueuserworkitem

srinathchow
srinathchow used Ask the Experts™
on
Hi I am new to c++ and I have written a c++ code to activate a process by doing Threadpool::QueueUserWorkitem which is going me nuts I can do that C# easily but c++ is not going good. Below is the code please help me. Thanks!

in the heade file I have 
static AutoResetEvent^ backgroundprocess;
backgroundprocess = gcnew AutoResetEvent(false);
 
and also declared the method in the header file as 
static void Process(Object^ signal);
 
in the main.cpp file the method Process and it's function was written as 
 
static void Process(Object^ signal)
{
 //method implementation
}
 
under the 
int main(array<System::String ^> ^args) I called
 System::Threading::ThreadPool::QueueUserWorkItem(gcnew WaitCallback(0,&Process),SSESchedulerHandler::backgroundprocess);
 
I am getting the error as 
 
Error 1 error C3350: 'System::Threading::WaitCallback' : a delegate constructor expects 1 argument(s)

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I got the solution for the above problem. Instead of declaring the Void Process(System^ Object) in the header file we have to declare it in the main.cpp file above the main. The solution looks like:

Solution code:

in the main.h heade file
static AutoResetEvent^ backgroundprocess;
backgroundprocess = gcnew AutoResetEvent(false);

in the main.cpp file

void Process(Object^ signal);
int main(array<System::String ^> ^args)
{
System::Threading::ThreadPool::QueueUserWorkItem(gcnew WaitCallback(&Process),SSESchedulerHandler::backgroundprocess);
}

static void Process(Object^ signal)
{ // do something  }

and this works.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial