LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

how to break a event callback

My problem is: when one event function is running after event_commit on the control, how to break it (in other words, stop running the funtion before it's over)?
 
Thanks very much!
Best regards
Jaman
Developing Test Sepcialist
0 Kudos
Message 1 of 9
(4,678 Views)
Use the following function inside your callback routine:  ProcessSystemEvents (void);
That will make any other functions on your UIR file available. Make a function that you can click that will
force your original callback to exit. 
 
0 Kudos
Message 2 of 9
(4,640 Views)
Jaman,

As a rule of thumb, you should not spend very much time in any given call of a callback function.  Using ProcessSystemEvents can be used as a workaround, but you might consider doing the task in a separate thread (see CmtScheduleThreadPoolFunction and related functions).  For example, you could have a control callback launch the second thread, which would do its processing in a loop, while checking a global flag (e.g. gKeepProcessing).  If you needed to stop the processing, you would just have your main thread clear the global flag.

Hope this helps.

Mert A.
National Instruments
0 Kudos
Message 3 of 9
(4,630 Views)
If I understand your question correctly, you wish to exit the callback function early?
 
You can simply issue a return 0; to exit normally or a return 1; to "swallow" the event.
 
If that is not what you want to do and you are looking to continue processing other UI events, you will either have to use the ProcessSystemEvents() call or figure out how to only handle UI events in your callback while handing off intensive processing to another thread (that is what I tend to do when I can).
 
Multithreading is quite a powerful tool but it takes a bit of planning to make it work right and for everything to be able to synchronize when you need it to.
Martin Fredrickson
Test Engineer

Northrop Grumman
Advanced Systems and Products
San Diego, CA 92128
0 Kudos
Message 4 of 9
(4,612 Views)
Thanks very much for your all great help, I use ProcessSystemEvents() first and it's ok but not the best, because the time for one loop of my program is too long, I'will try to use multithread.
 
one more quesetion, does one thread pool just mean one more thread, why use pool to describe, what 's the mean of ThreadPool please?
Best regards
Jaman
Developing Test Sepcialist
0 Kudos
Message 5 of 9
(4,551 Views)


@Jaman wrote:
 
one more quesetion, does one thread pool just mean one more thread, why use pool to describe, what 's the mean of ThreadPool please?



You are not limited neither to one thread pool only nor to one thread per thread pool. You can add more than one thread to the default thread pool and you can create a new thread pool with the ability to create a specified number of threads inside it.

The use of the default thread pool permits you to schedule a thread function without need to call CmtNewThreadPool () function before.

One hint to note, though, is that your computer has a limited number of processors inside (one only unless special configurations Smiley Wink ) and the processor(s) are in charge of all functions in the system: multiplying the number of threads can result in no performance improvement if you are consuming all processor(s) resources...



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 9
(4,543 Views)
Jaman,

You should think of a thread pool as a group of threads waiting around anxiously for you to give them tasks to do (by calling CmtScheduleThreadPoolFunction).  If you schedule more functions than there are threads in the pool, the function calls will get queued until one of the threads finishes its previous task and can take on a new job.  The more threads in your thread pool, the less more likely it is that scheduled thread pool functions will run immediately.  For your purposes, it seems like your thread function will finish before another such thread function is scheduled, so you shouldn't have to worry about this; just use the default thread pool.

Mert A.
National Instruments
0 Kudos
Message 7 of 9
(4,528 Views)
Hello Rorbert and Mert A,
 
After study your comment, my understanding is:
 
CVI use CmtScheduleThreadPoolFunction or CmtScheduleThreadPoolFunctionAdv to creat one thread, and then SYSTEM will check if idle thread exist, or creat new, but if there are maximum threads in the pool, the function wait. The system creat or arrange thread itself, so we don't need more function as CreatThread to creat one new thread.
 
I'm not sure if my comprehension if right or not, and could you kindly supply some example code for me? it's great the example can include all thread specailty inside, and I want to do a deep study for MultiThreads.
 
also, how to share data between thread, could you please include it also inside the example?
 
Thanks very much!
Best regards
Jaman
Developing Test Sepcialist
0 Kudos
Message 8 of 9
(4,515 Views)
 

Dear Jaman,

some literature and some examples are already included in CVI distribution and you can find them on your hard disk. I suggest you to look at MultithreadingOverview.pdf document located in <cvidir>\bin together with some other application notes from NI. As per the software, use the example finder to browse through the samples shipped with CVI: multithreading related samples can be found under "Optimizing Applications >> Multithreading".

Next you can search NI site for other documentation and samples: for example Multithreading in LabWindows/CVI
Multithreading in LabWindows/CVI document or Multithreading with a Modal Dialog Pop-up in LabWindows/CVI sample code.For this purpose, the Development Library for CVI is a rich and useful resource to deep into.


 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 9 of 9
(4,508 Views)