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

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

一、傻瓜式解决办法:

  删除:

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

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

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

二、妥善的解决办法

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

  

扫描二维码关注公众号,回复: 2138433 查看本文章

猜你喜欢

转载自www.cnblogs.com/amanda112/p/9299858.html