LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

.net odd issue

Hi Guys,

 

I've got a weird issue, which I can't seem to pick apart. 

 

I download the ni verified version of this, and it works just fine:

https://forums.ni.com/t5/Example-Code/Programmatically-Acquire-Screenshot-in-Executable-Application/...

 

Copy and past the contents into a new untitled.vi, and do no changes as far as I can tell, and all of a sudden I get this: 

Invoke Node Error calling method System.Drawing.Image.Save, (System.ArgumentNullException: Key cannot be null.
Parameter name: key) <append><b>System.ArgumentNullException</b> in Untitled 1

 

Anyone happen to know if there is something subtle with the .net invoke nodes that is tripping me up?


------------------------------------------------------------------------------------

Please join the conversation to keep LabVIEW relevant for future engineers. Price hikes plus SaaS model has many current engineers seriously concerned...

Read the Conversation Here, LabVIEW-subscription-model-for-2022
0 Kudos
Message 1 of 5
(1,017 Views)

Did you see that there's a comment at the top telling you that the preferred execution system must be set to "user interface"?  Did you do that on the new VI you copied it to?

0 Kudos
Message 2 of 5
(1,009 Views)

Well, no I didn't! Wow, that also appears to have solved my issue. 

 

I'll admit my ignorance on this "preferred execution system" setting, though. No idea why that affects this code. Any chance you know and could share a sentence or two?


------------------------------------------------------------------------------------

Please join the conversation to keep LabVIEW relevant for future engineers. Price hikes plus SaaS model has many current engineers seriously concerned...

Read the Conversation Here, LabVIEW-subscription-model-for-2022
0 Kudos
Message 3 of 5
(944 Views)

LabVIEW is fully multithreading. Some code doesn’t like to be called from different threads. The only easy way to guarantee this is to force all the relevant code to run in the UI thread. That is the only one that is guaranteed to run in the same thread in LabVIEW.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 5
(933 Views)

I would guess that in this case it's the first call that doesn't use .NET causing the issue, the one doing a virtual press of "print screen".  If that doesn't get triggered, then the second part expecting to find an image in the clipboard will find something else (probably the last text or whatever that you copied) and produce the error you saw.

 

I had to do something similar to this but I did it with an alternate .NET method (System.Drawing.Graphics.CopyFromScreen) and that one had no problem running in a "whatever" thread.

0 Kudos
Message 5 of 5
(914 Views)