473,396 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Threads & WindowsForms(a problem)

Hello there,
I have a problem with windows form that is
Iam trying to create a thread that needs to access my form
I defined a member function called func
void func()
{
//stuff
this->prop = val ;
}
then I created the thread in a button_click event like this
On_Button_Click(.....)
{
using namespace System::Threading ;
ThreadStart * TS = new ThreadStart(0,this->Func);
Thread * T = new Thread(TS);
T->Start();
}
when I compile I recieve an error message
Form1.h(78): error C3351: 'System::Threading::ThreadStart' :
if you pass a NULL object instance to a delegate constructor you must also
pass the address of a static member function

as you see it asks me to declare the "func" method as a static member function
the problem is that I need to use "this" pointer inside the "func" method so
I can't define it
as a static member function.
instead how can I pass a non-static method to the ThreadStart delegate? in
other words
what is the first parameter of the delegate which is of type "System::Object
__gc* "?

Thanks alot to you "reader"
Iam really in love with Microsoft® >>>.
Keep going >>>.

Nov 17 '05 #1
3 929
Try this:

ThreadStart * TS = new ThreadStart(this, &YourClass::func);

instead of
ThreadStart * TS = new ThreadStart(0,this->Func);
Hope this helps

Marcus Heege
ma****@heege.net
"Basel Al-Khateeb" <Ba************@discussions.microsoft.com> wrote in
message news:50**********************************@microsof t.com... Hello there,
I have a problem with windows form that is
Iam trying to create a thread that needs to access my form
I defined a member function called func
void func()
{
//stuff
this->prop = val ;
}
then I created the thread in a button_click event like this
On_Button_Click(.....)
{
using namespace System::Threading ;
ThreadStart * TS = new ThreadStart(0,this->Func);
Thread * T = new Thread(TS);
T->Start();
}
when I compile I recieve an error message
Form1.h(78): error C3351: 'System::Threading::ThreadStart' :
if you pass a NULL object instance to a delegate constructor you must
also
pass the address of a static member function

as you see it asks me to declare the "func" method as a static member
function
the problem is that I need to use "this" pointer inside the "func" method
so
I can't define it
as a static member function.
instead how can I pass a non-static method to the ThreadStart delegate? in
other words
what is the first parameter of the delegate which is of type
"System::Object
__gc* "?

Thanks alot to you "reader"
Iam really in love with Microsoft® >>>.
Keep going >>>.


Nov 17 '05 #2
I'm doing roughly the same thing and i tried this solution but i keep getting
error
error C2102: '&' requires l-value
Not sure how to resolve it either, any suggestion?
Jan 2 '06 #3
Hi,

i could not find the post that you are replying to. what was your original
problem?
my news reader doesn't have a thread for this discussion so i can't view the
original post.

kind regards,
Bruno.
"Zototh" <Zo****@discussions.microsoft.com> wrote in message
news:2E**********************************@microsof t.com...
I'm doing roughly the same thing and i tried this solution but i keep
getting
error
error C2102: '&' requires l-value
Not sure how to resolve it either, any suggestion?

Jan 2 '06 #4

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

Similar topics

8
by: Alban Hertroys | last post by:
Hello, I'm using psycopg to insert records in a number of threads. After the threads finish, another thread runs to collect the inserted data. Now, my problem is that psycopg let's my threads...
1
by: Codemonkey | last post by:
Hi, Sorry for the cross group post, but I couldn't find a group that deals with threading in .net. Anyway, I've noticed a difference in the way my program acts on Windows 98 than it does on...
0
by: Philip Greer | last post by:
I am getting the following issue with a first threads program I've written: root@aixsys1:/usr/local/bin # ./threadtest.pl Thread 1 with 0 and 10 to do something... Can't call method "tid"...
5
by: Leonardo Hyppolito | last post by:
Hello! I am trying to implement a program that uses Threads. I chose the producers and consumers scenario. The producers put a "product" (which is an int number) in a shared storage place of one...
1
by: Basel Al-Khateeb | last post by:
Hello there, I have a problem with windows form that is Iam trying to create a thread that needs to access my form so I have to define a class (MyClass) containing the thread method (Func) and the...
6
by: FoundThisOnline | last post by:
I have been searching online for a whole day and couldn't find an answer for this. I have this hyperlink server control: ------------------------------------------------ <asp:HyperLink...
4
by: Ashish_CPP | last post by:
Hi, Can anyone help me and suggest some good C books that enhances the logical & problem solving skills. I dont want those books which teach C/C++ rather I want those books to be suggested that...
1
by: vasilip | last post by:
Can anyone help me out with these two issues I seem to be having? using the db2 driver for PHP (db2_xxxxxx) functions 1. If I forget, or for some reason db2_commit/db2_rollback doesn't get...
0
by: Astan Chee | last post by:
Hi, I have 2 classes in python, the first one runs first and and then the first one calls the second class. I want it to run the second class as a separate thread but I want the first one to wait...
2
by: Gabriel Genellina | last post by:
En Tue, 13 May 2008 06:42:13 -0300, Astan Chee <stanc@al.com.auescribió: I'm confused trying to understand your requirements too. "run a class?" Threads execute code, it's easier to think of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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,...

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.