473,396 Members | 1,961 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.

Thread and callback

Hi,

When creating a thread, how do I make it loop until a specific condition
happen to make it end?

Just for instance, I want a thread to loop until (appl. is closed) to
perform actions on items within a collection.

Does it need a callback function?

Thanks you

Marty
Nov 21 '05 #1
5 1534
When you start your thread, you chose what procedure it starts... However
you can pass in a state object (using thread pool) or set whatever
properties you want to a custom class using the Thread.Start method (which
has no parameters allowed to be sent in, but you can just set these in
properities)

The easiest way to do it from that point is adding a andling to
Application.Exit, Application.Exception, and Application.ThreadException
that will then notify the class that is running on the separate thread that
something died. and go from there. But you still need to have a loop that
says

While not bHasExited

'WARNING put in a sleep timer here because it will eat up a lot of cycle
time just looping.

Wend


"Marty" <xm******@hotmail.com> wrote in message
news:oGwfd.8352$df2.3864@edtnps89...
Hi,

When creating a thread, how do I make it loop until a specific condition
happen to make it end?

Just for instance, I want a thread to loop until (appl. is closed) to
perform actions on items within a collection.

Does it need a callback function?

Thanks you

Marty

Nov 21 '05 #2
When you start your thread, you chose what procedure it starts... However
you can pass in a state object (using thread pool) or set whatever
properties you want to a custom class using the Thread.Start method (which
has no parameters allowed to be sent in, but you can just set these in
properities)

The easiest way to do it from that point is adding a andling to
Application.Exit, Application.Exception, and Application.ThreadException
that will then notify the class that is running on the separate thread that
something died. and go from there. But you still need to have a loop that
says

While not bHasExited

'WARNING put in a sleep timer here because it will eat up a lot of cycle
time just looping.

Wend


"Marty" <xm******@hotmail.com> wrote in message
news:oGwfd.8352$df2.3864@edtnps89...
Hi,

When creating a thread, how do I make it loop until a specific condition
happen to make it end?

Just for instance, I want a thread to loop until (appl. is closed) to
perform actions on items within a collection.

Does it need a callback function?

Thanks you

Marty

Nov 21 '05 #3
Hi

you can periodically check a boolean variable in the loop of the thread and
if it is true, exit the loop. Or you can wait very short time for an event
and if it is signaled by application you exit the loop. Another option is
sending a message to the thread by PostThreadMessage API which informs it to
exit the loop. In the last option you need to check your message queue. In
all the ways you should Join to this thread in main application thread to
make sure it is finished before closing the application.
"Marty" wrote:
Hi,

When creating a thread, how do I make it loop until a specific condition
happen to make it end?

Just for instance, I want a thread to loop until (appl. is closed) to
perform actions on items within a collection.

Does it need a callback function?

Thanks you

Marty

Nov 21 '05 #4
Hi

you can periodically check a boolean variable in the loop of the thread and
if it is true, exit the loop. Or you can wait very short time for an event
and if it is signaled by application you exit the loop. Another option is
sending a message to the thread by PostThreadMessage API which informs it to
exit the loop. In the last option you need to check your message queue. In
all the ways you should Join to this thread in main application thread to
make sure it is finished before closing the application.
"Marty" wrote:
Hi,

When creating a thread, how do I make it loop until a specific condition
happen to make it end?

Just for instance, I want a thread to loop until (appl. is closed) to
perform actions on items within a collection.

Does it need a callback function?

Thanks you

Marty

Nov 21 '05 #5
Hi

you can periodically check a boolean variable in the loop of the thread and
if it is true, exit the loop. Or you can wait very short time for an event
(autoreset or manual) and if it is signaled by application you exit the loop.
Another option is sending a message to the thread by PostThreadMessage API
which informs it to exit the loop. In the last option you need to check your
message queue. In all the ways you should Join to this thread in main
application thread to make sure it is finished before closing the application.
"Marty" wrote:
Hi,

When creating a thread, how do I make it loop until a specific condition
happen to make it end?

Just for instance, I want a thread to loop until (appl. is closed) to
perform actions on items within a collection.

Does it need a callback function?

Thanks you

Marty

Nov 21 '05 #6

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

Similar topics

3
by: Travis Berg | last post by:
I'm running into a problem when trying to perform a callback to a Python function from a C extension. Specifically, the callback is being made by a pthread that seems to cause the problem. If I...
1
by: scott ocamb | last post by:
hello I have implemented a solution using async methods. There is one async method that can be invoked multiple times, ie there are multiple async "threads" running at a time. When these...
31
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...
12
by: serge calderara | last post by:
Dear all, I have a function that I need to run in a thread due to the fact that it can takes long time to execute according to the amount of data to collect. This function is also populating a...
1
by: johnny | last post by:
In a multi-threaded application, say a worker thread makes an asynchronous call and specifies a callback method. But before the callback is executed, the thread is aborted by its creator. What is...
8
by: Mountain Bikn' Guy | last post by:
I'm using async delegate calls. I would like to re-enter my initial thread after the callback. (I'm not using UI controls, so Control.Invoke is not the solution.) How can I manually implement...
4
by: Bob Rock | last post by:
Hello, I was wondering if callback delegates, called in response to a event, are executed in their own thread. I was suspecting the OS might spawn a new thread and have the delegate execute in...
5
by: admin | last post by:
ok This is my main. Pretty much it goes through each category and starts up 4 worker threads that then ask for groups to gether from. My problem is that when the thread gets done it keeps the...
4
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
6
by: HolyShea | last post by:
All, Not sure if this is possible or not - I've created a class which performs an asynchronous operation and provides notification when the operation is complete. I'd like the notification to be...
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: 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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.