LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

run in the background

Hi,

 

I just wanted to know if it is possible to run a CVI in the back ground.

Meaning that after lunching my application, make the all panel dsappear but running in the background... Is this possible and how?

 

Thank you

0 Kudos
Message 1 of 6
(3,926 Views)

These are related but different concepts.

 

You can cause the GUI panel not to appear simply by not displaying it.  You can just load it and not display it.

 

But not displaying the panel doesn't cause the process to somehow be a "background" process, it just means you can't see the loaded panel.

 

It depends on what you mean by "background".  This usually means a low priority task that runs only when other "foreground" tasks are not running.  This is enforced on Windows OS's by process priority class and the thread priority.

 

You set process priority with the SetPriorityClass() function.

 

You can set the process priority to BELOW_NORMAL_PRIORITY_CLASS  or   IDLE_PRIORITY_CLASS and the OS will schedule other process's threads ahead of those in the process of interest.

 

Windows OS's are designed to run processes at the NORMAL_PRIORITY_CLASS (the default) for a good balance of execution times amongst a group of processes.

 

What happens is that all of the threads in the process are grouped in priority over a range of thread priorities.  All scheduling is done on a thread basis:  processes aren't scheduled.

 

You can set individual thread priorities with the SetThreadPriority() function.  But you may well have only a single application thread, though the CVI RTE itself is multi-threaded and can create threads "behind the scenes" so to speak, depending upon which libraries you're using.

 

A quick way to set a process to low priority is with this call:

 

SetProcessPriorityClass (GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS);

 

use this at the startup of your process in the WinMain function, and don't use the DisplayPanel() function.

 

Process and thread priority and scheduling is a surpsingly complex topic in Windows, but changing the process priority as above may do what you want.

 

 

Message 2 of 6
(3,922 Views)

Thanks a lot.

0 Kudos
Message 3 of 6
(3,910 Views)

Thanks so much menchar! I was looking for a way to do this too, and the BELOW_NORMAL_PRIORITY_CLASS worked perfectly. Much appreciated!

0 Kudos
Message 4 of 6
(3,902 Views)

On re-reading your question, I see I didn't really answer it completely.

 

You can load and display the panels as needed at process startup, then when you're ready to go "background", hide the panels with   HidePanel()    calls, then set the process priority class to below normal or idle.

 

This does beg the question as to how you'll get the process to ever stop 😉  You could use the task manager to kill it I suppose. 

 

Better yet would be to lower the process priority class and then minimize the panel to the task bar, CVI supports this on more recent versions with  the   MinimizeAllWindows()   function. 

 

Or, enable the taskbar for your panel and then just have the user minimize it when done with the GUI.  You will see some automatic priority decrease for a minimized process, but maybe not enough for what you want.  I don't know how to easily get a callback for when the user minimizes using the taskbar (so that you could lower the process priorty class).

0 Kudos
Message 5 of 6
(3,892 Views)

I'm also curious to know how he would get it to stop.

 

Timing is one way.

 

If it is looking for an event is another, such as a keystroke.

 

If part of the program is to check if the program is already running, and if it does detect it already running, shut both processes off, then by "running" the program a second time, you would be in fact shutting it off. I think I like that idea the most, because I'm unsure of whether a keystroke could be detected if the focus is taken off of the CVI program. It also allows for setting up windows' scheduled tasks to auto-run and stop the program and setting of hotkeys to run it.

0 Kudos
Message 6 of 6
(3,870 Views)