Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by voidmain11 · Oct 05, 2016 at 03:44 AM · dllhidecpu usagec# dllminimize

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

2.png (82.7 kB)
1.png (144.0 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Fragmental · Oct 02, 2018 at 06:33 PM

Does Application.targetFrameRate work?

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image aeroson · Feb 17 at 12:31 PM 0
Share

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

avatar image aeroson · Feb 21 at 01:59 PM 0
Share

Fixed this by doing Thread.Sleep to force 60 FPS

avatar image
0

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?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

76 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Sending output to USBm device (Scent Palette) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges