Threads & WindowsForms(a problem)

G

Guest

Hello there,
I have a problem with windows form that is
Iam trying to create a thread that needs to access my form
I defined a member function called func
void func()
{
//stuff
this->prop = val ;
}
then I created the thread in a button_click event like this
On_Button_Click(.....)
{
using namespace System::Threading ;
ThreadStart * TS = new ThreadStart(0,this->Func);
Thread * T = new Thread(TS);
T->Start();
}
when I compile I recieve an error message
Form1.h(78): error C3351: 'System::Threading::ThreadStart' :
if you pass a NULL object instance to a delegate constructor you must also
pass the address of a static member function

as you see it asks me to declare the "func" method as a static member function
the problem is that I need to use "this" pointer inside the "func" method so
I can't define it
as a static member function.
instead how can I pass a non-static method to the ThreadStart delegate? in
other words
what is the first parameter of the delegate which is of type "System::Object
__gc* "?

Thanks alot to you "reader"
Iam really in love with Microsoft® >>>.
Keep going >>>.
 
M

Marcus Heege

Try this:

ThreadStart * TS = new ThreadStart(this, &YourClass::func);

instead of
ThreadStart * TS = new ThreadStart(0,this->Func);

Hope this helps

Marcus Heege
(e-mail address removed)
 
G

Guest

I'm doing roughly the same thing and i tried this solution but i keep getting
error
error C2102: '&' requires l-value
Not sure how to resolve it either, any suggestion?
 
B

Bruno van Dooren

Hi,

i could not find the post that you are replying to. what was your original
problem?
my news reader doesn't have a thread for this discussion so i can't view the
original post.

kind regards,
Bruno.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top