473,320 Members | 2,147 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,320 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 1530
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.