09-27-2013 03:43 AM
Hi,
I have a problem with Custom Controls in a multi-thread CVI program.
Here's what I do: Thread 2 opens a connection to a GigE Camera, creates a Custom Control and displays a live video from now on. Thread 1 handles all the rest. Whenever there are a larger number of user events (clicking buttons or moving the program window) the Custom Control freezes and the program crashes.
As the Custom Control functions are non-thread-safe I made sure that thread 2 uses ImageControl_ functions only. However NI Vision and NI IMAQdx create addition threads that might cause a problem.
I've attached a small program that demonstrates this effect. Click "Start Test" to create a Custom Control and show a live video. Normally the program won't crash at this point. Press "Enable Timer" to enable a timer that ticks 10 times per second and resize or move the program window. These additional events will cause a program crash.
Does anybody of you know this effect?
mju_
09-30-2013 05:12 AM
Hello,
I think we need to separate the processing and display.
For exemple you can use an Timer to display image and use Thread to processing
Good day
10-02-2013 01:56 AM
Hello,
maybe I haven't got the point yet but how does the timer help? As the custom control routines are non-thread-safe, the timer callback will have to run in the second thread as well, so there is no real change...?
_mju
10-02-2013 04:37 PM
Hi mju,
I haven't looked at your code but if I understand your description you are interacting with a user interface control from a thread other than the main thread, This is generally not allowed on Windows (or any platform for that matter). Even if you restrict you usage of it to a single thread, any interaction with the OS (UI events, etc) all come in via the main thread and so will potentially collide.
Eric
10-08-2013 03:42 AM
Eric,
tank you for your reply.
I thought that I'm allowed to work on controls from (nearly) every thread. In the helpfiles I found a page (Panels and Multithreating). It says: