Link to home
Start Free TrialLog in
Avatar of klay8
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->InvokeRequired == false)
            {
            stp=this->progressBar1->Step*rnd->Next(-1,2);
            newval = this->progressBar1->Value + stp;

            if (newval > this->progressBar1->Maximum)
                  newval = this->progressBar1->Maximum;
            else if (newval < this->progressBar1->Minimum)
                  newval = this->progressBar1->Minimum;

            this->progressBar1->Value = newval;
            }
      else
            {
                  DelegateThreadTask ^myThreadDelegate = gcnew DelegateThreadTask(this,ThreadTask());
            this->Invoke(myThreadDelegate);      
            
            }
}
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::DelegateThreadTask' : 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::ThreadStart' : a delegate constructor expects 2 argument(s)
can anyone help please
regards
klay
Avatar of zveljkovic
zveljkovic
Flag of Serbia image

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?
Avatar of klay8
klay8

ASKER

ok this is the file
http://www.mediafire.com/?zhthlbegigc
thanks for ur help
ASKER CERTIFIED SOLUTION
Avatar of zveljkovic
zveljkovic
Flag of Serbia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of klay8

ASKER

thanks it's done
Avatar of klay8

ASKER

hi again
i would like to use some parameters in the thread function..
how can i pass parameters
thanks