[solved]probelm of cpu usage when hide application by windwos.dll
hi, I am developing standalone application by unity3d. I has function of tracking which program is running while user use computer.
so i used plugin dll to hide application while it tracking programs.
Here's the code
[DllImport("user32.dll")]
public static extern int ShowWindow(int hwnd, int nCmdShow);
public void hide_application()
{
Main_Handle = GetActiveWindow();
ShowWindow(Main_Handle,0);
}
BUT, HERE'S A QUESTION.
as you can see in screenshot. when i hide application. the cpu usage increase so highly. It would be quite annoying, when user use another program. how can i decrease cpu usage and also hide application. please help me. thanks
please don't reply why don't use visual studio c# instead of unity3d. ^^*
Answer by voidmain11 · Oct 06, 2016 at 06:16 AM
Well, i solved this. I think i am genius a little. anyway. here we go.
I think the problem has occured because unity3d doesn't recognize of being hided by windows. so i assume that unity3d application tried to find out where she is now.
The evidence of this hypothesis is increase of update_count. when i log the update_count during hide of application. the update_count increase so rapidly 10000 times per second. it's generally 150 times per seceond.
so i solved this problem by following way.
if (show_hide)
{
mcanvas.gameObject.SetActive(true);
mcamera.gameObject.SetActive (true);
EventSystem.gameObject.SetActive (true);
gameObject.SetActive (true);
ShowWindow (Main_Handle, SW_SHOW);
}
else
{
mcanvas.gameObject.SetActive(false);
mcamera.gameObject.SetActive (false);
EventSystem.gameObject.SetActive (false);
gameObject.SetActive (false);
Main_Handle = GetActiveWindow ();
ShowWindow (Main_Handle, SW_HIDE);
}
I unactived every single function and object before hide. an reavtivated before show again.
And to work tracking_process during unactiv, i used InvokeRepeating, instead of startcoroutine.
thanks.
Answer by Fragmental · Oct 02, 2018 at 06:33 PM
Does Application.targetFrameRate work?
The issue seems to be fixed when WPF app is minimized. But when I click on TabItem that is empty and the element that Unity is in is hidden away, then Unty has 4000 FPS
Answer by ProKillerMT · Jan 08 at 03:29 PM
I know I'm 6 years late but I have the problem with the high cpu usage "50%" (I'm trying to hide the unity3D game window), anyone found a way to fix it?
Your answer
Follow this Question
Related Questions
How to minimize application on Mac OS 0 Answers
Classes that inherit UIBehaviour in a DLL no longer visible in Unity editor. 2 Answers
Using #if UNITY_DEBUG in DLLs 0 Answers
Unity don't recognize scripts 0 Answers