这个问题有点轶事,但对我来说仍然很有趣;我想知道为什么 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:\Proyectos\beanstalk\dotnetfx\trunk\WinSvc101\WinSvc101\Service101.cs 69 0
任何评论将不胜感激。提前非常感谢。