0

私はVS2005標準版を持っています.MSはこれを言います:

注: Windows サービス アプリケーション プロジェクト テンプレートおよび関連する機能は、Visual Basic および Visual C# .NET の Standard Edition では使用できません...

VS2005 Standard エディションをアップグレードせずに Windows サービス アプリケーションを作成することはできますか?

4

3 に答える 3

1

カットアンドペーストができれば、例で十分です。

別のサービスのステータスを定期的にログに記録する単純なサービス。この例にはServiceInstaller クラス(サービス アプリケーションのインストール時にインストール ユーティリティによって呼び出される) が含まれていないため、インストールは手動で行われます。

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);
        }
    }
}
于 2008-11-13T13:06:12.890 に答える
0

はい、ここを見てください:

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

于 2008-11-13T12:55:43.940 に答える
0

もちろん、自分でコードを書く必要があります。実際にはそれほど難しいことではありません。その方法については、次の 2 つのリファレンスを参照してください。

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/

于 2008-11-13T12:57:56.353 に答える