klay8
asked on
c++ threading
hi
i tryed to make a simple application fro threads using a microsoft example:
http://support.microsoft.com/kb/815805
i made the changes to be like this:
delegate void DelegateThreadTask();
private: void ThreadTask()
{
int stp;
int newval;
Random ^rnd=gcnew Random();
if (progressBar1->InvokeRequi red == false)
{
stp=this->progressBar1->St ep*rnd->Ne xt(-1,2);
newval = this->progressBar1->Value + stp;
if (newval > this->progressBar1->Maximu m)
newval = this->progressBar1->Maximu m;
else if (newval < this->progressBar1->Minimu m)
newval = this->progressBar1->Minimu m;
this->progressBar1->Value = newval;
}
else
{
DelegateThreadTask ^myThreadDelegate = gcnew DelegateThreadTask(this,Th readTask() );
this->Invoke(myThreadDeleg ate);
}
}
private: void repeat()
{
while(true)
{
ThreadTask();
Thread::Sleep(100);
}
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
ThreadStart ^myThreadDelegate = gcnew ThreadStart(this, repeat);
trd = gcnew Thread(myThreadDelegate);
trd->IsBackground = true;
trd->Start();
}
i still have those errors:
1.error C3364: 'thread1::Form1::DelegateT hreadTask' : invalid argument for delegate constructor; delegate target needs to be a pointer to a member function
2.error C3867: 'thread1::Form1::repeat': function call missing argument list; use '&thread1::Form1::repeat' to create a pointer to member
3.error C3350: 'System::Threading::Thread Start' : a delegate constructor expects 2 argument(s)
can anyone help please
regards
klay
i tryed to make a simple application fro threads using a microsoft example:
http://support.microsoft.com/kb/815805
i made the changes to be like this:
delegate void DelegateThreadTask();
private: void ThreadTask()
{
int stp;
int newval;
Random ^rnd=gcnew Random();
if (progressBar1->InvokeRequi
{
stp=this->progressBar1->St
newval = this->progressBar1->Value + stp;
if (newval > this->progressBar1->Maximu
newval = this->progressBar1->Maximu
else if (newval < this->progressBar1->Minimu
newval = this->progressBar1->Minimu
this->progressBar1->Value = newval;
}
else
{
DelegateThreadTask ^myThreadDelegate = gcnew DelegateThreadTask(this,Th
this->Invoke(myThreadDeleg
}
}
private: void repeat()
{
while(true)
{
ThreadTask();
Thread::Sleep(100);
}
}
private: System::Void Form1_Load(System::Object^
ThreadStart ^myThreadDelegate = gcnew ThreadStart(this, repeat);
trd = gcnew Thread(myThreadDelegate);
trd->IsBackground = true;
trd->Start();
}
i still have those errors:
1.error C3364: 'thread1::Form1::DelegateT
2.error C3867: 'thread1::Form1::repeat': function call missing argument list; use '&thread1::Form1::repeat' to create a pointer to member
3.error C3350: 'System::Threading::Thread
can anyone help please
regards
klay
Hi. I see that you are using managed c++. Can You post your entire project on some free file hosting service ( i prefer www.mediafire.com ) so i can check your code?
ASKER
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 it's done
ASKER
hi again
i would like to use some parameters in the thread function..
how can i pass parameters
thanks
i would like to use some parameters in the thread function..
how can i pass parameters
thanks