[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. ^^*


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.

Does Application.targetFrameRate work?

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?