Saturday, February 7, 2015

[Solved - I think ] Visual Studio High CPU usage

Out of nowhere I started Visual Studio to get some coding happening, and it was almost unusable.

I was editing a CSHTML file, and the CPU usage was through the roof. At one point the CPU usage was over 40% and my Surface Pro 3 started heating up and the only thing I could do was to shutdown Visual Studio.

I don't know why this is happening I was working on the same file last night without a hitch. Here is a screenshot of task manager:




























I'm suspecting that this is has something to do with JS and editing CSHTML files. When I edit a normal class everything is hunky dory.

Just an update: 

I tried closing some of the files, and restarted it. When I open one particular CSHTML file in my solution the CPU idles at 40%. I cannot share the code since it is part of a project. When I close the file it drops back 0% or 1%.




Another Update - I think I've worked it out.


I did some testing as to what was happening, I have a file I was doing some tests on called uploadFiles.cshtml. This was html to manage a ajax file upload. I was looking to integrate this functionality into my overall project.


  1. I opened uploadFiles.cshtml - The CPU usage hit 40% and bounced around from 30+% to 40%. I copied all the code and created a new CSHTML file (newupload.cshtml), pasted all the code without modifications. Once I closed  uploadFiles.cshtml and only newupload.cshtml was open the CPU usage went back down. Strange. I initially thought that it was because I had comments using the razor syntax with references to stackoverflow questions and answers and blog posts while I conducted my tests. 
  2. I closed VS and opened newupload.cshtml and everything was normal. I closed VS again, and reopened VS and this time I opened uploadFiles.cshtml. The CPU hit 40%. So now I realised that it wasn't the code in the uploadFiles.cshtml. Just to make sure I deleted all the code in uploadFiles.cshtml and replaced it with some normal markup. The CPU was still bouncing around from 30% to 40%. The only conclusion i could make is that there is something odd with the file. 
  3. I checked the file permissions and folder locations to make sure that there isn't something odd (like the file is located on another network share or USB etc...). But nothing was out of the ordinary. 
  4. I then checked the Solution, and then I noticed something. The uploadFiles.cshtml was excluded from the project. I then included the file into the project and the CPU was 0%-1% and everything was fine. I repeated this by excluding the file from the solution and re-opened the file and the CPU went to about 40%.  


My Conclusion


My conclusion at this stage is that there is something odd happening with opening excluded files in your solution. If you have this issue then try the following:

  1. Close the open file
  2. Right click on the file in your solution explorer and go to Include In Project. 
  3. Open file 

see if this works, it seems to be working for me. 




0 comments:

Post a Comment