473,779 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Thread, parameter passing

I am tring to start a thread where I am passing info into thread. According
to MS documentation I must do this by creating a class for that thread. I
have done this but am getting a compiler error. The error is:

c:\T02010_NET_o ra9\cgi-bin\programs\Ti meReader\TimeRe aderWinService. cpp(104):
error C2475: 'ThreadWithStat e::readerThread ' : forming a pointer-to-member
requires explicit use of the address-of operator ('&') and a qualified name

When I try to place '&' in what I believe is proper place I get a syntax
error on illegal use of '&'
I did have this line working before I tried to move it to this new class
with parameters. Below I have example of non working line and working line:
NON WORKING:
readThread = new Thread (new ThreadStart(thi s,
tws->ThreadWithStat e::readerThread ));

WORKING:
readThread = new Thread (new
ThreadStart(thi s,&TimeReaderWi nService::reade rThread));

Below is a little more complete listing of code so you can see I have
declared things:
public __gc class TimeReaderWinSe rvice : public
System::Service Process::Servic eBase
{
private:
Thread *readThread;
void readerThread (void);
protected:
/// <summary>
/// Set things in motion so your service can do its work.
/// </summary>
void OnStart(String* args[]);
private:
};

public __gc class ThreadWithState {
public:
ThreadWithState (Queue *queue_ptr);
void readerThread (void);
int ParseEmpcode (StreamWriter *fip, String*& empcode, String *data, int
track,
int leadskip, int tailskip, char skipzero);

// State information used in the task
private:
Queue *mySyncdQ;
};

void TimeReaderWinSe rvice::OnStart( String* args[])
{
Queue *myQ,
*mySyncdQ;
Thread *readThread;

myQ = new Queue();
mySyncdQ = Queue::Synchron ized(myQ);
ThreadWithState *tws = new ThreadWithState (mySyncdQ);

// TODO: Add code here to start your service.
// Start a separate thread that does actual reading
if((readThread == NULL) || (readThread->ThreadState &
(System::Thread ing::ThreadStat e::Unstarted |
System::Threadi ng::Stopped)) !=
(System::Thread ing::ThreadStat e)0) {
//This is the line that is having the problem
readThread = new Thread (new ThreadStart(thi s,
tws->ThreadWithStat e::readerThread ));

// readThread = new Thread (new
ThreadStart(thi s,&TimeReaderWi nService::reade rThread));
readThread->Start();
}

}
Dec 19 '05 #1
3 1823
brian_harris wrote:
I am tring to start a thread where I am passing info into thread.
According to MS documentation I must do this by creating a class for
that thread. I have done this but am getting a compiler error. The
error is:

c:\T02010_NET_o ra9\cgi-bin\programs\Ti meReader\TimeRe aderWinService. cpp(104):
error C2475: 'ThreadWithStat e::readerThread ' : forming a
pointer-to-member requires explicit use of the address-of operator
('&') and a qualified name


You need:

//This is the line that is having the problem
readThread = new Thread (new
ThreadStart(tws ,&ThreadWithSta te::readerThrea d));

-cd
Dec 19 '05 #2
Thanks,
That got me past my compiler problem. Do you have an recomendations on
books for learning manged C++. I have microsoft visual C++ .NET step by step
version 2003. While it gave me a good introduction, it does not provide
enough information on what other classes are avaible and how to use them.
Microsofts online examples are so simplified I have not been able to easly
map them to real life usage. So I am looking for a more complete reference
to manged C++.

"Carl Daniel [VC++ MVP]" wrote:
brian_harris wrote:
I am tring to start a thread where I am passing info into thread.
According to MS documentation I must do this by creating a class for
that thread. I have done this but am getting a compiler error. The
error is:

c:\T02010_NET_o ra9\cgi-bin\programs\Ti meReader\TimeRe aderWinService. cpp(104):
error C2475: 'ThreadWithStat e::readerThread ' : forming a
pointer-to-member requires explicit use of the address-of operator
('&') and a qualified name


You need:

//This is the line that is having the problem
readThread = new Thread (new
ThreadStart(tws ,&ThreadWithSta te::readerThrea d));

-cd

Dec 19 '05 #3
brian_harris wrote:
Thanks,
That got me past my compiler problem. Do you have an recomendations
on
books for learning manged C++. I have microsoft visual C++ .NET step
by step version 2003. While it gave me a good introduction, it does
not provide
enough information on what other classes are avaible and how to use
them. Microsofts online examples are so simplified I have not been
able to easly
map them to real life usage. So I am looking for a more complete
reference
to manged C++.


Actually, I'd recommend getting VC++ 2005 and switching to C++/CLI. It's
much more capable and plays better with the rest of the .NET framework.

For VC 7.1 managed C++, this book is usually well thought of:

http://www.amazon.com/gp/product/073...lance&n=283155

-cd
Dec 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
2511
by: AlexeiOst | last post by:
Everywhere in documentation there are recommendations to use threads from thread pooling for relatively short tasks. As I understand, fetching a page or multiple pages (sometimes up to 50 but not tipical) from the Internet and doing some processing on those would be considered to be a big/long task for a thread from a pool. In our app it is possible to break the task into some small ones (thread per fetch and processing thereafter or event...
2
18406
by: Job Lot | last post by:
How can I pass parameters to a procedure which is called in thread? '! Spin off a new thread. myThread = New Thread(New ThreadStart(AddressOf GetRawFigures)) myThread.IsBackground = True myThread.Start() Procedure GetRawFigures takes an argument as follows: Private Sub GetRawFigures(ByVal figures As Integer())
2
2189
by: Carlos | last post by:
Hi all, I am familiar with passing parameters to a thread function using C++, but I needt to learn it using C#. Can someone shed some light on how to do this? Code snippets will be great to show me. Thanks in advance, Carlos
2
3218
by: Claudio Biagioli | last post by:
I start a parallel thread inside a control with the following code: Private Sub StartParallelProc(ByVal Command As SqlClient.SqlCommand) Dim T As New Threading.Thread(AddressOf ParallelProc) Command.Parameters("MyID").Value = Guid.NewGuid.ToString System.Web.HttpContext.Current.Session("ID") = Command
7
2695
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have a lock pending, for example. I want to be able to stop a thread temporarily, and then optionally resume it or stop it for good.
3
1894
by: JohnnyGr | last post by:
I have heard theres a new way to start threads with parameters in framework 2.0, does anyone know how to do that? this is what i need to do... Start a thread that executes some stuff, in this case it does gets all files from a directory. then i need to update the GUI with information from the thread... the thread should be started with a parameter, in this case its a string
3
1901
by: kplkumar | last post by:
I want to call a method passing a parameter. I want to do this call on a seperate thread. For example, public class Foo { public static void FooSend(Message message) { // Start a seperate thread to call Send(message) method // everytime someone calls this FooSend method }
6
6871
by: Sergey Poberezovskiy | last post by:
I have the following code in C# that I have trouble converting to VB(2.0): private delegate void openDialog(); private void openWindowsDialog(openDialog open) { Thread thread = new Thread(new ThreadStart(open)); thread.SetApartmentState(ApartmentState.STA); thread.Start(); }
2
3736
by: JackC | last post by:
Hi, I create my threads like this: for(int j = 0; j < 5; j++) { boost::thread *thr = new boost::thread(worker_func); threads.add_thread(thr); }
8
9433
by: asit | last post by:
How do I pass parameters to created thread..here is the code(but it can't pass data..it uses global variable) #include <windows.h> #include <stdio.h> DWORD Sum; DWORD WINAPI Summation(LPVOID Param) {
0
9632
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8958
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7478
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.