Visual C++ threading

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

FerrisWheel

Thread Starter
Joined
Jan 13, 2010
Messages
24
Following the threading tutorials given on MSDN, I am unable to create a thread in visual c++. I have the code:
Code:
System::Threading::ThreadStart^ threaddelegate = gcnew System::Threading::ThreadStart( &Form1::listen );
System::Threading::Thread^ lThread = gcnew System::Threading::Thread( threaddelegate );
lThread->Start();
Gives me an error that ThreadStart requires two parameters, I look and find that in the examples, the tutorial uses an instance of the same class that contains the function. Trying to input a Form or the instance of Form1 gives an error. What do I place in the first parameter?
The tutorial
 

FerrisWheel

Thread Starter
Joined
Jan 13, 2010
Messages
24
I tried the code:
Code:
System::Threading::ThreadStart^ threaddelegate = gcnew System::Threading::ThreadStart( NULL, &Form1::listen );
But it gave me the errors:
Code:
error C2440: 'initializing' : cannot convert from 'int' to 'Client::Form1 ^'
error C3754: delegate constructor: member function 'Client::Form1::listen' cannot be called on an instance of type 'int'
 
Joined
Sep 25, 2007
Messages
290
If listen() is not static, you must pass an instance of Form1 as the first parameter.
 

FerrisWheel

Thread Starter
Joined
Jan 13, 2010
Messages
24
And how would I do this? I'm using managed Visual C++ code. The declaration of the class uses:
Code:
public ref class Form1 : public System::Windows::Forms::Form
	{
 
Joined
Sep 25, 2007
Messages
290
I've never used ThreadStart myself, but if you are invoking it from within an instance of Form1, I'd reckon you could just pass it the this pointer.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top