C# 因缺少CategoryName,而未能初始化 的解决办法

 

群里一小伙伴在开发APP时遇到了问题,便截图提问

一、傻瓜式解决办法:

  删除:

  ((System.ComponentModel.ISupportInitialize)(this.performanceCounter1)).EndInit();

  这个办法虽然简单,但是会出错。

  原因是,当你添加performanceCounte之类的控件时,它会要求生成CategoryName,但VS突然犯傻,没有自动生成CategoryName,所以报了错。(CategoryName指的就是控件要用的名字)

 

二、妥善的解决办法

  在Form1.Designer中添加
    this.performanceCounter1.CategoryName = "Processor";
    this.performanceCounter1.CounterName = "% Processor Time";
    this.performanceCounter1.InstanceName = "_Total";

  

 

————————————假装这是一个分割线————————————

posted @ 2018-07-12 15:50  阿曼达  阅读(957)  评论(0编辑  收藏  举报