Click to See Complete Forum and Search --> : Have ThreadStart run unmanaged method?


nice_guy_mel
August 8th, 2007, 02:07 PM
I have an unmanaged class. In old Microsoft Visual Studio 6, this classed used a 3rd party library to implement threads. Now that we are moving our projects into the .Net framework, I wanted to re-write the class to use System::Threading::Thread instead of our 3rd party library. I was hoping it would be as simple as having a

gcroot<Thread^> m_pThread;

member variable, and then use it to start running my Run() method. Now I'm not certain if it is even possible. From what I've read about the Thread constructor, it requires a ThreadStart object. The ThreadStart object constructor requires a handle to a System::Object. This implies that you can only have a Thread launch methods from Managed Classes, and not Unmanaged Classes. Is this indeed the case?

There is a second ThreadStart constructor that takes in a void(*)(void) parameter... could this be something I could use?

thegrinch
August 9th, 2007, 05:37 AM
Hi!

Well, I think the easiest way aroudn your problem would be to build a wrapper class around your unmanages function. This wrapper class would in principle just execute your unmanaged procedure in its working method. look also here (http://codeguru.earthweb.com/columns/dotnet/article.php/c4609/)

best regards

thegrinch

nice_guy_mel
August 11th, 2007, 12:56 PM
Wrapper classes are used when you want to separate the managed/unmanaged world. I want the opposite, I want to combine them. I was pleased to see that .Net has provided a way to have Unmanaged member variables in a managed class and vice versa, but I'm just stuck on the syntax involved in trying to use a managed Thread class to call an unmanaged method. It could very well be that this is not supported at all. But when I saw that one of the parameters to ThreadStart was void(*)(void), I thought maybe this was how you get it to work with unmanaged functions.

nice_guy_mel
August 23rd, 2007, 12:21 PM
Anybody know about the void(*)(void) parameter from ThreadStart?