Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / November 2006

Tip: Looking for answers? Try searching our database.

ThreadPool Error Compiling, Pointer To Member.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gnassar@gmail.com - 17 Nov 2006 08:14 GMT
This question is prob. extremely trivial but I can't seem to find out
what is going on. I've been doing some basic work with Multithreading
and Worker Threads and have determined I'd like to set up a minor
project that has ThreadingPools.

I can't seem to get it to compile whether I follow the example
tutorials or I don't. Of course the latter has a higher percentage of
failing :)

Anyways the line that fails is:
ThreadPool::QueueUserWorkItem(gcnew
System::Threading::WaitCallback(t->ThreadCallBack),i);

The examples don't show anything being passed into the function but
it's a bit necessary for me to have each of the threads know what
numbers they are. So I'd really like to send in the number they are.

The function I'm sending them to is:
void dthread::ThreadCallBack(Object^ threadContext){
..
...
..
}

Now the errors I get all have to do with delegation of functions or
with pointers. I assumed that with this being a managed project I
didn't have to deal with most of that.

Errors:
Error    1    error C3867: 'dthread::ThreadCallBack': function call missing
argument list; use '&dthread::ThreadCallBack' to create a pointer to
member

Error    2    error C3350: 'System::Threading::WaitCallback' : a delegate
constructor expects 2 argument(s)

Before you go about telling me that I shouldn't be using -> to point to
the function in the class allow me to tell you that my function is
*not* static. Furthermore I have instantiated the class before hand.
I"ve been following two tutorials from msdn, one does it, the other
doesn't.

Ie:

for (int i = 0; i........;  i++){
MRE[i] = gcnew ManualResetEvent(false);
dthread^ t = gcnew dthread(this->clb_List->Items[a]->ToString(),
MRE[i]);
WTHREAD[i] = t;
System::UInt32^ m_i = gcnew UInt32(i);
ThreadPool::QueueUserWorkItem(gcnew
System::Threading::WaitCallback(t->ThreadCallBack),i);
}

Now I can make one of them go away by removing the parameter or even
moving the parameter into the WaitCallback but I dont think thats
right. Can anyone point me into the right direction.

TIA.
G
Ben Voigt - 24 Nov 2006 18:01 GMT
> This question is prob. extremely trivial but I can't seem to find out
> what is going on. I've been doing some basic work with Multithreading
[quoted text clipped - 8 lines]
> ThreadPool::QueueUserWorkItem(gcnew
> System::Threading::WaitCallback(t->ThreadCallBack),i);

That's how C# would do it...

In C++/CLI you need
ThreadPool::QueueUserWorkItem(gcnew System::Threading::WaitCallback(t,
&dthread::ThreadCallBack),i);

> The examples don't show anything being passed into the function but
> it's a bit necessary for me to have each of the threads know what
[quoted text clipped - 22 lines]
> the function in the class allow me to tell you that my function is
> *not* static. Furthermore I have instantiated the class before hand.

Doesn't matter.  You can only refer to a member function by the class name,
not by an instance.

> I"ve been following two tutorials from msdn, one does it, the other
> doesn't.
[quoted text clipped - 17 lines]
> TIA.
> G

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.