小第才用C#最近试着写了一个服务但是不知道为什么在安装服务的时候老是提示格式不对我把代码贴出来大家给研究下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;namespace testSrv
{
    public partial class testSrv : ServiceBase
    {
        public testSrv()
        {
            InitializeComponent();
        }        private System.IO.FileSystemWatcher myWatcher;
        protected override void OnStart(string[] args)
        {
            // TODO: 在此处添加代码以启动服务。
            myWatcher = new System.IO.FileSystemWatcher("c:\\", "*.*");
            myWatcher.IncludeSubdirectories = true;
            myWatcher.InternalBufferSize = myWatcher.InternalBufferSize * 2;
            myWatcher.Created += new System.IO.FileSystemEventHandler(myWatcher_Created);
            myWatcher.EnableRaisingEvents = true;
        }        protected override void OnStop()
        {
            // TODO: 在此处添加代码以执行停止服务所需的关闭操作。
            myWatcher.EnableRaisingEvents = false;
        }        private void myWatcher_Created(object sender, System.IO.FileSystemEventArgs e)
        {
            System.IO.StreamWriter wt = new System.IO.StreamWriter(@"e:\test.txt",true);
            wt.WriteLine(e.FullPath + "被创建");
            wt.Close();
        }
    }
}

解决方案 »

  1.   

    是用 InstallUtil.exe 安装的?
      

  2.   

    //加上试试static void Main()
    {
    System.ServiceProcess.ServiceBase[] ServicesToRun;
    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new testSrv () }; System.ServiceProcess.ServiceBase.Run(ServicesToRun);
    }
      

  3.   

    using System.Collections.Generic;
    using System.ServiceProcess;
    using System.Text;namespace testSrv
    {
        static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            static void Main()
            {
                ServiceBase[] ServicesToRun;            // 同一进程中可以运行多个用户服务。若要将
                // 另一个服务添加到此进程中,请更改下行以
                // 创建另一个服务对象。例如,
                //
                //   ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
                //
                ServicesToRun = new ServiceBase[] { new testSrv() };            ServiceBase.Run(ServicesToRun);
            }
        }
    }我是用VS2005写的
    谁叫我QQ我把代码打包传给他帮我看看