Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Using callback function written in C# with IMAQ

Hello Everyone.

 

I’m not sure if I’m posting this on a right board or not,,,, but please help me.

 

The problem I am facing is that a callback function which set with a NI-IMAQ function “imgSessionWaitSignalAsyn2” are collected by Garbage Collection before it is actually called. 

 

Does anybody know how I can prevent a callback function from being collected by GC and keep alive until it is called???

 

 

Thanks

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

Hello

This is saha from National Instruments.Thanks for contacting us.

I am afraid to say that I dont understand you properly.So far I know, the Garbage Collection is a system for automactic memory management.Could you give me the detail you mean by "allback function which set with a NI-IMAQ function “imgSessionWaitSignalAsyn2” are collected by Garbage Collection".Do you want to tell that your callback function is not being executed?What language are you using?I would suggest you to try any sample program shipped with the NI-IMAQ or NI-Vision driver which is using callback function in it.What happens when you run you program.If there is any error please let me know.

Waiting to hear from you.

Best of luck.

saha/Applications  Engineering/National Instruments,Japan

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

Hi. 

 Thanks for your attention. 

Let me explain a bit more about what I tried to ask before.  

As a programming language, I use C#.  I have checked some sample programs distributed by NI, but they are written in C so that I assume Garbage Collection problem ever happens with these samples. 

When I run my application, it is ok if callback functions are called as long as Garbage Collection does not run and do any memory management stuff.   However, when my application is used, it will be waiting for an external trigger for a couple hours so that Garbage Collection will run for sure.  Then, if an external trigger comes into my grabber board, an error message shows up.

Hopefully, this helps you understand what I tried to ask before.

 Thank you for your help.

    TantoK

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

Hi,

==================================================================
>>When I run my application, it is ok if callback functions are called as long as Garbage Collection does not run and do any memory management
stuff.   However, when my application is used, it will be waiting for an external trigger for a couple hours so that Garbage Collection will run for sure.  Then, if an external trigger comes into my grabber board, an error message shows up.
==================================================================

I am not sure, I understand your problem here. In C# the garbage collection is always running. Instances of classes will be deleted by the garbage collector as soon as they are identified as no more referenced. And this is surely quicker than a couple of hours. Are you sure your delegate is referenced by some objects when you get your external trigger?

Can you may be explain more what you are doing here? Or may be any example?

Regards,
Risotto

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