473,386 Members | 1,764 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,386 software developers and data experts.

passing data between threads

Hi, I have multi-threaded application that requires one particular thread
(Non-Form based) to receive data from other threads. I know how to pass
control to Form Threads, but I believe there's no way to pass to Non-Form
Threads. So the only two solutions I can think of to handle this situation
is to (1) Keep the Non-Form Thread as is and set up a polling method to
watch for shared variables and respond appropriately, or (2) change the
Class to a Form so I can pass control to it from other threads.

Is there any other (and hopefully easier) way besides two way approaches
above??

Nov 21 '05 #1
10 8550
depending upon your needs, a mutex or a semaphore may be more
appropriate. polling can get expensive.

can you give more details on your specific needs?

Nov 21 '05 #2
It doesn't have to specifically be a Form - a Control will do. I can remember
times when I've derived a worker class from Control purely in order to use
the InvokeMember method.
"Mark Denardo" wrote:
Hi, I have multi-threaded application that requires one particular thread
(Non-Form based) to receive data from other threads. I know how to pass
control to Form Threads, but I believe there's no way to pass to Non-Form
Threads. So the only two solutions I can think of to handle this situation
is to (1) Keep the Non-Form Thread as is and set up a polling method to
watch for shared variables and respond appropriately, or (2) change the
Class to a Form so I can pass control to it from other threads.

Is there any other (and hopefully easier) way besides two way approaches
above??

Nov 21 '05 #3
Hi,

I would create a wrapper class to handle the thread. I would
add methods to start and stop the thread to the class. I also would add
some properties to accept the data you want to pass to the thread.

Ken
--------------------
"Mark Denardo" <ma*********@runbox.com> wrote in message
news:Y9********************@comcast.com...
Hi, I have multi-threaded application that requires one particular thread
(Non-Form based) to receive data from other threads. I know how to pass
control to Form Threads, but I believe there's no way to pass to Non-Form
Threads. So the only two solutions I can think of to handle this situation
is to (1) Keep the Non-Form Thread as is and set up a polling method to
watch for shared variables and respond appropriately, or (2) change the
Class to a Form so I can pass control to it from other threads.

Is there any other (and hopefully easier) way besides two way approaches
above??


Nov 21 '05 #4
"Bonj" <Bo**@discussions.microsoft.com> schrieb
It doesn't have to specifically be a Form - a Control will do. I can
remember times when I've derived a worker class from Control purely
in order to use the InvokeMember method.

If the other thread doesn't have a message loop, it will not execute the
invoked member.
Armin

Nov 21 '05 #5
I don't really understand how a control will help without a form in the
first place. Here's the big picture of my needs:

I have a central "Server" Thread that is a Form that I use to watch all
Client activity on and I have a "ListenToClients" Thread that in non-Form
based, that just sits and listens for Client requests and actions. I also
have a number of lets just call them "ClientsInteracting" Threads (non-Form
based) that are created by the server which allow Clients to interact and do
things. I have possibly a lot of these (could get up to 100-200 or so), so
I set them up in their own threads, because up to 10-20 clients could be
interacting on each of these threads and sending everything to the Server to
manage all this wouldn't be practical.

When a client wants to do or say something, it comes in on the
"ListenToClients" (non-Form) Thread and needs to get passed to the
"ClientsInteracting" (non-Form) thread somehow without burdening the Server
(Form) Thread.

So a passing data to a control doesn't help, unless I first make
"ClientsInteracting" a Form. Right? Or am I missing something.
"Bonj" <Bo**@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
It doesn't have to specifically be a Form - a Control will do. I can
remember
times when I've derived a worker class from Control purely in order to use
the InvokeMember method.
"Mark Denardo" wrote:
Hi, I have multi-threaded application that requires one particular thread
(Non-Form based) to receive data from other threads. I know how to pass
control to Form Threads, but I believe there's no way to pass to Non-Form
Threads. So the only two solutions I can think of to handle this
situation
is to (1) Keep the Non-Form Thread as is and set up a polling method to
watch for shared variables and respond appropriately, or (2) change the
Class to a Form so I can pass control to it from other threads.

Is there any other (and hopefully easier) way besides two way approaches
above??

Nov 21 '05 #6
Here's the big picture of my needs:

(repeated from a reply on another post:)
I have a central "Server" Thread that is a Form that I use to watch all
Client activity on and I have a "ListenToClients" Thread that in non-Form
based, that just sits and listens for Client requests and actions. I also
have a number of lets just call them "ClientsInteracting" Threads (non-Form
based) that are created by the server which allow Clients to interact and do
things. I have possibly a lot of these (could get up to 100-200 or so), so
I set them up in their own threads, because up to 10-20 clients could be
interacting on each of these threads and sending everything to the Server to
manage all this wouldn't be practical. When a client wants to do or say
something, it comes in on the "ListenToClients" (non-Form) Thread and needs
to get passed to the "ClientsInteracting" (non-Form) thread somehow without
burdening the Server (Form) Thread.

So when you say wrapper, you're talking about setting up a wrapper in an
already Formed Thread, that would control the "ClientsInteracting"
(non-Form) Thread? If this is what you're referring to, then in my case it
won't work, because I need to pass from (non-Form) Thread to (non-Form)
Thread.
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:Ot**************@TK2MSFTNGP09.phx.gbl...
Hi,

I would create a wrapper class to handle the thread. I would
add methods to start and stop the thread to the class. I also would add
some properties to accept the data you want to pass to the thread.

Ken
--------------------
"Mark Denardo" <ma*********@runbox.com> wrote in message
news:Y9********************@comcast.com...
Hi, I have multi-threaded application that requires one particular thread
(Non-Form based) to receive data from other threads. I know how to pass
control to Form Threads, but I believe there's no way to pass to Non-Form
Threads. So the only two solutions I can think of to handle this situation
is to (1) Keep the Non-Form Thread as is and set up a polling method to
watch for shared variables and respond appropriately, or (2) change the
Class to a Form so I can pass control to it from other threads.

Is there any other (and hopefully easier) way besides two way approaches
above??

Nov 21 '05 #7
When you say "message loop", your referring to what a Form does right? I'm
still trying to understand what the Framework does under the cover...

Because if I'm trying to pass data from one non-Form Thread to another
non-Form Thread, it doesn't work because the Non-Form thread doesn't have a
message loop - meaning if it ran out of things to do, it would just end,
where as if it's a form it sits and waits for user interaction. Is my
understanding correct here?

So that's why a non-Form Thread would need to set up polling, else it would
just end right?
"Armin Zingler" <az*******@freenet.de> wrote in message
news:ur**************@TK2MSFTNGP15.phx.gbl...
"Bonj" <Bo**@discussions.microsoft.com> schrieb
It doesn't have to specifically be a Form - a Control will do. I can
remember times when I've derived a worker class from Control purely
in order to use the InvokeMember method.

If the other thread doesn't have a message loop, it will not execute the
invoked member.
Armin

Nov 21 '05 #8
Oh man, now your making me look up what semaphores and mutex do again. Here
the bigger picture, while I look these up:

(repeated from a reply on another post:)
I have a central "Server" Thread that is a Form that I use to watch all
Client activity on and I have a "ListenToClients" Thread that in non-Form
based, that just sits and listens for Client requests and actions. I also
have a number of lets just call them "ClientsInteracting" Threads (non-Form
based) that are created by the server which allow Clients to interact and do
things. I have possibly a lot of these (could get up to 100-200 or so), so
I set them up in their own threads, because up to 10-20 clients could be
interacting on each of these threads and sending everything to the Server to
manage all this wouldn't be practical. When a client wants to do or say
something, it comes in on the "ListenToClients" (non-Form) Thread and needs
to get passed to the "ClientsInteracting" (non-Form) thread somehow without
burdening the Server (Form) Thread.

I'm thinking that just setting the "ClientsInteracting" thread up as a form
will make all this go away...
"stand__sure" <st*********@hotmail.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
depending upon your needs, a mutex or a semaphore may be more
appropriate. polling can get expensive.

can you give more details on your specific needs?

Nov 21 '05 #9
"Mark Denardo" <ma*********@runbox.com> schrieb
When you say "message loop", your referring to what a Form does
right?
http://msdn.microsoft.com/library/en...sagequeues.asp

I'm still trying to understand what the Framework does under
the cover...
Application.Run contains the message loop. Control.BeginInvoke is a function
sending a kind of message to the thread that created the Control.
Application.Run processes this message. Without a message loop, the message
is not processed (I don't mention Application.Doevents here...).
Because if I'm trying to pass data from one non-Form Thread to
another non-Form Thread, it doesn't work because the Non-Form thread
doesn't have a message loop - meaning if it ran out of things to do,
it would just end, where as if it's a form it sits and waits for
user interaction. Is my understanding correct here?

So that's why a non-Form Thread would need to set up polling, else
it would just end right?

I think these are two different things: Notification and lifetime of a
thread.

I'm not a thread-notification specialist. I would probably add a "job" entry
into a collection that is available to both threads (the sender and the
receiver) and use Synclock for synchronisation.

And yes, the thread ends because there is nothing to do anymore.
Application.run contains the message loop that keeps the thread alive.
Armin

Nov 21 '05 #10
we seem to be going in circles here.

your code needs some way to "listen". an event driven model makes the
most sense (if this is truly a single application and not several).

if I correctly your scenario, you will have a variable number of
clients. this means that if you choose the polling approach, you will
possibly have to poll a variable number of objects. in general polling
is a bad idea and in your instance would be a VERY bad idea since it
will create a lot of excess work on the thread, etc. this is why
mutexes and semaphores were suggested.

Ken Tucker's suggestion about wrapping the thread in a class is
EXCELLENT advice -- you should ALWAYS do this (i.e. his advice extends
beyond your current needs.

at this point, SAMPLE CODE would be helpful! your description is
beginning to sound like MULTIPLE PROCESSES and not multiple threads.
Code would be most helpful.

to avoid spinning you in circles with generalities, if you have code
that gives you "illegal cross thread operation" errors, you are on the
right path -- if you post that code here, we can help you make it
work...

Nov 21 '05 #11

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

Similar topics

1
by: Rob Oliver | last post by:
Hi, I've seen a walkthrough for passing data from a setup project to a custom action (an application) with an InstallClass. I am curious though--can the data also be intercepted by a custom...
3
by: Simon Harvey | last post by:
Hi, In my application I get lots of different sorts of information from databases. As such, a lot of information is stored in DataSets and DataTable objects. Up until now, I have been passing...
1
by: Hans [DiaGraphIT] | last post by:
Hi! I have problem with passing data to custom action. I don't know what wrong I'm doing. I'm trying to follow the steps in the walkthrough: "Passing Data to a Custom Action" ...
3
by: Brian Smith | last post by:
I have a .aspx page (we'll call it Form1) with a datagrid on it. The datagrid is populated from a dataset that I manually entered data into (the data isn't in a database). The datagrid on Form1...
3
by: Marc Castrechini | last post by:
First off this is a great reference for passing data between the Data Access and Business Layers:...
0
by: Dave Cullen | last post by:
I have a dll written in VC6 that I need to send arguments to from a call in VB.NET. I'm having trouble passing data arguments between them. So far I've only tried passing strings, and all I get...
3
by: Lonewolf | last post by:
Hi all, I'm having difficulties passing data back to managed class from my native class when the data is generated from within a native thread in the native class itself. I will give the following...
4
by: moondaddy | last post by:
I have a htm page where I need to pass some data to an aspx page as a means of sending data to the database. I don't need to see the aspx page so I was going to put it in a hidden iframe. This...
4
by: Dameon99 | last post by:
Hi all, I am passing data into a function in C to be edited but that function already returns some data. I was wondering how i could pass data in to a function so that when it is edited it is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.