srinathchow
asked on
pass the method from c++ to C# for ThreadPool.QueueUserWorkItem
Hi I am trying to something like
I have a method called process written in c++. and trying to do ThreadPool.QueueUserWorkIt em(process ) in C#. This ThreadPool.QueueWorkItem is defined in C# in the constructor in a class
So, I got the instance of that class in c++ and trying to pass the c++ method to the C# file for Threadpool.
Any help is greatly appreciated! Thanks a lot!
I have a method called process written in c++. and trying to do ThreadPool.QueueUserWorkIt
So, I got the instance of that class in c++ and trying to pass the c++ method to the C# file for Threadpool.
Any help is greatly appreciated! Thanks a lot!
Example Code:
C# code:
public delegate void Process();
public class ThreadClass
{
//Constructor
public ThreadClass(Process del,string x)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(0,del), x);
}
}
c++ code:
int main(array<System::String ^> ^args)
{
string x = "something";
//when the below call is made the prcess must be queusd for work
ThreadClass(&process,x);
}
static void process()
{
// do something
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help Omego!
I am lookiing for the 3rd scenario and tried it. I directly used the Threadpool::QueueUserWorkI tem in c++ and it works. I am trying it pass it to C# for Queuing because I am new to c++ and I got errors which got no success.
The mistake i am doing is i am declaring the void Process(System ^ Object) in main.h instead of main.cpp file. By following your above steps mentioned in 3 solved my problem.
code:
using namespace main;
void Process(Object^ signal);
int main(array<System::String ^> ^args)
{
String ^x = "something";
System::Threading::ThreadP ool::Queue UserWorkIt em(gcnew WaitCallback(&Process,x);
}
static void Process(Object^ signal)
{ //do something }
Thanks a lot!
I am lookiing for the 3rd scenario and tried it. I directly used the Threadpool::QueueUserWorkI
The mistake i am doing is i am declaring the void Process(System ^ Object) in main.h instead of main.cpp file. By following your above steps mentioned in 3 solved my problem.
code:
using namespace main;
void Process(Object^ signal);
int main(array<System::String ^> ^args)
{
String ^x = "something";
System::Threading::ThreadP
}
static void Process(Object^ signal)
{ //do something }
Thanks a lot!
public delegate void Process(object test);
public class ThreadClass
{
public ThreadClass(Process del, string x)
{
ThreadPool.QueueUserWorkIt
}
}
2. Declare your process method in C++ as follows:
Void process(Object ^ee){MessageBox::Show("add
3. To use the delegate, use this code:
String ^x = "something";
ClassLibrary1::Process ^pro = gcnew ClassLibrary1::Process(thi
ClassLibrary1::ThreadClass