02-27-2023 03:18 PM
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:
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?
02-27-2023 03:41 PM
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?
02-28-2023 07:00 AM - edited 02-28-2023 07:00 AM
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?
02-28-2023 08:42 AM
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.
02-28-2023 11:46 AM
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.