Solved

c++ threading

Posted on 2008-06-15
5
1,202 Views
Last Modified: 2013-12-14
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
0
Comment
Question by:klay8
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 4

Expert Comment

by:zveljkovic
ID: 21790066
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?
0
 

Author Comment

by:klay8
ID: 21790145
ok this is the file
http://www.mediafire.com/?zhthlbegigc
thanks for ur help
0
 
LVL 4

Accepted Solution

by:
zveljkovic earned 500 total points
ID: 21790287
Hi. I have corrected your code.
Link to the project is
http://www.mediafire.com/?ftlnrjnmgnm

I had some strange compile time error which i solved by commenting out a #include "stdafx.h" and disabling Use Precompiled header from project properties.
The main problem was that pointer to member function of class is not just nameOfFunction but namespace::ClassName::Function. Just see in project.
btw nice effect :D

Hope that helps,
Zlax
0
 

Author Comment

by:klay8
ID: 21790308
thanks it's done
0
 

Author Comment

by:klay8
ID: 21800096
hi again
i would like to use some parameters in the thread function..
how can i pass parameters
thanks
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question