Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem multi-thread CVI program & NI Vision Custom Controls

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_

 

0 Kudos
Message 1 of 5
(4,511 Views)

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

0 Kudos
Message 2 of 5
(4,487 Views)

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

0 Kudos
Message 3 of 5
(4,463 Views)

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

0 Kudos
Message 4 of 5
(4,449 Views)

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:

 

If you create a child panel, you must do so in the same thread in which you create or load the top-level panel. You can create controls other than timer controls in any thread.
 
However, my problems seems to indicate that this is not completely true for Custom Controls...
 
mju
0 Kudos
Message 5 of 5
(4,416 Views)