473,773 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Worker thread exits when from loads. Why?

Hi,

I have this windows app that I'm working on. When it loads it
instantiates this object which creates a thread to read data and send
it to the form. My problem is, is that I want to keep this thread
around for the lifetime of the object, reading and sending data to the
from, but it seems to exit when the form completed loading.

Why is it doing this? And is there a way I can keep it around after
the form loads, without the form actually knowing anything about the
thread.

THanks

Aug 31 '07 #1
4 1179
I'm assuming this is obvious but make sure your thread variable stays in
scope after initialization. If the form stays visible, you can make the
object that creates the thread an instance variable. Make sure the actual
thread variable within the object stays in scope too.
Aug 31 '07 #2
On Aug 31, 11:09 am, "Jayme.Pech an" <ja...@pechan.u swrote:
I'm assuming this is obvious but make sure your thread variable stays in
scope after initialization. If the form stays visible, you can make the
object that creates the thread an instance variable. Make sure the actual
thread variable within the object stays in scope too.
Yes thank you. It is staying in scope. The thread variable is a
class scop instance variable. And the class is also a class scope
instance variable in the form.

Aug 31 '07 #3
DaTurk wrote:
I have this windows app that I'm working on. When it loads it
instantiates this object which creates a thread to read data and send
it to the form. My problem is, is that I want to keep this thread
around for the lifetime of the object, reading and sending data to the
from, but it seems to exit when the form completed loading.

Why is it doing this? And is there a way I can keep it around after
the form loads, without the form actually knowing anything about the
thread.
There is no need to keep the Thread instance referenced. A thread isn't
going to go away until the thread procedure (that is, the method that's
the entry point for the thread) exits. So the other reply is off-base
in implying that this is required.

On the other hand, the converse is also true. A thread _will_ go away,
always, if the thread procedure exits. There's nothing you can do about
this. It's how threads work.

As far as your specific question goes, it's not clear what you're trying
to do or what code you're using. The simple answer is "don't let the
thread's thread procedure exit". You don't actually describe what "this
object" is, or how it's implemented, but that's the basic answer.

On the other hand, the more general idea of what you're describing is
probably more appropriately solved using the existing thread pool.
Commonly the BackgroundWorke r class is used for this, though you can use
the thread pool directly as well if you like.

With more details about your specific scenario, you may receive more
specific and useful advice.

Pete
Aug 31 '07 #4
Hi,

"DaTurk" <mm******@hotma il.comwrote in message
news:11******** *************@y 42g2000hsy.goog legroups.com...
Hi,

I have this windows app that I'm working on. When it loads it
instantiates this object which creates a thread to read data and send
it to the form. My problem is, is that I want to keep this thread
around for the lifetime of the object, reading and sending data to the
from, but it seems to exit when the form completed loading.
The thread should ends when the method ends. It has no connection with the
form loading process (at least from your post)

Why is it doing this? And is there a way I can keep it around after
the form loads, without the form actually knowing anything about the
thread.
Why would you want to have a form without doing nothing?
Aug 31 '07 #5

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

Similar topics

2
1793
by: T Conti | last post by:
Hello: I created a basic windows service that polls a db and sends emails to our subscribers. In the onstart method I create a new thread and send it on its way to do work. It should never end unless told to do so by the onexit event I implemented in the worker object. However there are the rare circumstance that the thread hits a catastrophic error and exits the main process loop. So basically the service is now useless. Is there...
3
2542
by: Marcel van den Hof | last post by:
Dear all, Is there any way to prevent the ASP.NET worker process from recycling the worker process when a thread is being executed on the foreground (IsBackground=false). I'd also like to know if there a way for a foreground thread to detect if the worker process is being recycled? It seems that when a worker process recycles (under IIS 5.0) a thread
6
4997
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing for long running reports. When the processing is complete it uses crystal reports to load a template file, populate it, and then export it to a PDF. It works fine so far....
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.
6
5994
by: Joe Jax | last post by:
I have an object that spawns a worker thread to process one of its methods. That method processes methods on a collection of other objects. During this processing, a user may request to cancel the entire operation. I could request abort on the worker thread, but that is a) potentially messy, and b) not guaranteed to take immediate effect anyway. I would rather have some way of allowing the main thread to tell the worker thread that it...
5
3548
by: Soren S. Jorgensen | last post by:
Hi, In my app I've got a worker thread (background) doing some calculations based upon user input. A new worker thread might be invoked before the previous worker thread has ended, and I wan't only one worker thread running at any time (if a new worker thread start has been requested, any running worker thread results will be invalid). I'm using the below method to invoke a new worker thread, but when stress testing this I'm sometimes...
3
3284
by: Bill Davidson | last post by:
All: I have a problem in which a worker thread in my (.dll) assembly isn't allowing the main (.exe) assembly from terminating. Here's the scenario: 1) App.Exe is launched. 2) App.Exe calls into my .dll (Sub.Dll)
1
1707
by: EricBlair | last post by:
Hello, I've written a simple app as a test to run multiple threads from a pool. I'm able to do this, but what's happening is that the main thread finishes before all the workers do. So the Console shows: "Main thread exits." in between the worker thread strings. Can anyone see what I'm doing wrong please? Thanks in Advance! Here's my code:
2
1119
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
Using Visual Studio 2005 Professional: I have two thread routines in one project at this time. One came from me dropping a BackgroundWorker component on my form and setting the properties for it. Whenever this worker completes, I return the results back to the main form using DoWork's DoWorkerEventArgs variable, which has the Result object that I can set before the thread exits. Another worker thread in this project is constructed on...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
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...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8937
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
7463
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
5355
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...
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.