c# – Visual Studio 2008警告关于Designer生成的代码的更改
发布时间:2020-12-15 23:52:49 所属栏目:百科 来源:网络整理
导读:这个问题有点轶事,但对我来说仍然很有趣;我想知道为什么Visual Studio 2008不喜欢以下常量使用: public class Service101 : ServiceBase{ /// remarks /// Shown at Start - Settings - Control Panel - Administrative Tools - Services /// /remarks inte
这个问题有点轶事,但对我来说仍然很有趣;我想知道为什么Visual Studio 2008不喜欢以下常量使用:
public class Service101 : ServiceBase { /// <remarks> /// Shown at Start -> Settings -> Control Panel -> Administrative Tools -> Services /// </remarks> internal const string SERVICE_NAME = "WinSvc101"; /// <remarks> /// Shown at Start -> Settings -> Control Panel -> Administrative Tools -> Services /// </remarks> internal const string DISPLAY_NAME = "Windows Service 101"; /// <summary> /// Public constructor for Service101. /// </summary> public Service101() { InitializeComponent(); } private void InitializeComponent() { this.ServiceName = Service101.SERVICE_NAME; this.EventLog.Source = Service101.DISPLAY_NAME; this.EventLog.Log = "Application"; if (!EventLog.SourceExists(Service101.DISPLAY_NAME)) { EventLog.CreateEventSource(Service101.DISPLAY_NAME,"Application"); } } #region Events /// <summary> /// Dispose of objects that need it here. /// </summary> /// <param name="disposing">Whether or not disposing is going on.</param> protected override void Dispose(bool disposing) { // TODO: Add cleanup code here (if required) base.Dispose(disposing); } 因为它在设计时显示以下警告: Warning 1 The designer cannot process the code at line 68: if (!EventLog.SourceExists(DISPLAY_NAME)) { EventLog.CreateEventSource(DISPLAY_NAME,"Application"); } The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again. E:ProyectosbeanstalkdotnetfxtrunkWinSvc101WinSvc101Service101.cs 69 0 任何评论都会非常感激.非常感谢提前. 解决方法
将代码添加到InitializeComponent()时,设计人员不满意.尝试这样的事情:
public Service101() { InitializeComponent(); this.createEventSource(); } private void InitializeComponent() { this.ServiceName = SERVICE_NAME; this.EventLog.Source = DISPLAY_NAME; this.EventLog.Log = "Application"; } void createEventSource() { if (!EventLog.SourceExists(DISPLAY_NAME)) { EventLog.CreateEventSource(DISPLAY_NAME,"Application"); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |