首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有VS2005模板的Windows服务

没有VS2005模板的Windows服务
EN

Stack Overflow用户
提问于 2008-11-13 12:50:54
回答 3查看 615关注 0票数 0

我有VS2005标准版,MS说:

注意: Windows应用程序项目模板和相关功能在Visual和VisualC#.NET标准版中不可用。

在不升级VS2005标准版的情况下,可以编写Windows应用程序吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2008-11-13 13:06:12

如果你能剪切和粘贴,一个例子就足够了。

定期记录另一个服务状态的简单服务。该示例不包括ServiceInstaller类 (在安装服务应用程序时由安装实用程序调用),因此安装是手动完成的。

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Timers;

namespace SrvControl
{
    public partial class Service1 : ServiceBase
    {
        Timer mytimer;
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            if (mytimer == null)
                mytimer = new Timer(5 * 1000.0);
            mytimer.Elapsed += new ElapsedEventHandler(mytimer_Elapsed);
            mytimer.Start();
        }

        void mytimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            var srv = new ServiceController("MYSERVICE");
            AppLog.Log(string.Format("MYSERVICE Status {0}", srv.Status));
        }

        protected override void OnStop()
        {
            mytimer.Stop();
        }
    }
    public static class AppLog
    {
        public static string z = "SrvControl";
        static EventLog Logger = null;
        public static void Log(string message)
        {
            if (Logger == null)
            {
                if (!(EventLog.SourceExists(z)))
                    EventLog.CreateEventSource(z, "Application");

                Logger = new EventLog("Application");
                Logger.Source = z;
            }
            Logger.WriteEntry(message, EventLogEntryType.Information);
        }
    }
}
票数 1
EN

Stack Overflow用户

发布于 2008-11-13 12:55:43

是的,看这里:

http://www.codeproject.com/KB/system/WindowsService.aspx

票数 0
EN

Stack Overflow用户

发布于 2008-11-13 12:57:56

当然,你只需要自己写代码就行了。其实并不难。下面是几个关于如何做这件事的参考:

http://msdn.microsoft.com/en-us/magazine/cc301845.aspx

http://www.aspfree.com/c/a/C-Sharp/Creating-a-Windows-Service-with-C-Sharp-introduction/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/286835

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档