没有工作的C#Windows服务

问题描述

| 我已经创建了一个C#Windows服务,该服务应该发送一些电子邮件,但是当我启动该服务时,会收到消息“本地服务已启动,然后停止了”。。。做\' 为什么会这样呢?
namespace EmailService
{
public partial class EmailService : ServiceBase
{
    private System.Timers.Timer _timer = null;
    private DateTime _lastRun = DateTime.Now;
    private int _timerIntervalValue;

    public EmailService()
    {
        InitializeComponent();
    }

    protected override void OnStart(string[] args)
    {

        if (string.IsNullOrEmpty(ConfigurationManager.AppSettings[\"Timer\"]))
        {
            throw new Exception(\"The timer value is not set in the app.config.\");
        }
        else
        {
            _timerIntervalValue = Convert.ToInt32(ConfigurationManager.AppSettings[\"Timer\"]);
        }

        _timer = new System.Timers.Timer(_timerIntervalValue);
        _timer.Elapsed += OnTimedEvent;
        _timer.Interval = Convert.ToInt32(_timerIntervalValue);
        _timer.Enabled = true;

    }

    protected override void OnStop()
    {
        _timer.Stop();
        _timer.Dispose();
    }

    private void OnTimedEvent(object source,ElapsedEventArgs e)
    {
        Email email = new Email();
        email.ProcessEmails();
        _lastRun = DateTime.Now;
        _timer.Start();
    }


}

}
事件日志条目 服务无法启动。 System.Security.SecurityException:找不到源,但是无法搜索某些或所有事件日志。不可访问的日志:安全性。    在System.Diagnostics.EventLog.FindSourceRegistration处(字符串源,字符串machineName,布尔值readOnly)    在System.Diagnostics.EventLog.SourceExists(字符串源,字符串machineName)    在System.Diagnostics.EventLog.SourceExists(字符串源)     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)