Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Overlay on separate thread

Hello,

 

I'm trying to add a simple overlay on a image using a secondary thread. When I execute the

 

AxCWIMAQViewer1.Image.Overlays.Item(1).DrawRectangle(m_rectangle, CWIMAQOverlayModes.cwimaqOverlayModePaint,

                                         System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Aqua))

 

function I have a COMException error. If I run the same function in the main thread (for exemple on the click event of a button) the function work correctly. I attach my simple project and the bitmap of the error.

 

Thank You for the help.

 

Gualtiero

  

Download All
0 Kudos
Message 1 of 5
(3,853 Views)

Hi Gualtiero,

 

I'm taking care of your issue. Thanks for the example and the attached screenshot; I'll work on it and reply to this thread as soon as possible.

 

Best regards,

 

Fabio

Fabio M.
NI
Principal Engineer
0 Kudos
Message 2 of 5
(3,816 Views)

Hi Gualtiero,

 

I've found the reason why you're getting this error: you can share the Rectangle object on separate thread siche we don't support multi-thread with our ActiveX control. It is single threaded apartment (STA).

See http://www.codeproject.com/KB/COM/CCOMThread.aspx for a good overview.

Sorry for the delay of the reply,

 

Best regards,

 

Fabio

Fabio M.
NI
Principal Engineer
0 Kudos
Message 3 of 5
(3,798 Views)

Hi Fabio,

 

      Thank You very much for your explanation. Do You think that new releases of the National Vision ActiveX will be support multi thread application?

 

 

Gualtiero

 

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

Another solution for you will be to mashall all the ActiveX calls on the HMI thread ...... you will haev to right plenty of delegates for the HMI thread to execute synchronously when your background thread  needs it.

 

 

It is a serious disavantage   but it works fine 😞

 

Otherwise, think about going back to C++    

0 Kudos
Message 5 of 5
(3,728 Views)