Romoting 第一个例子

View Code
 public class RemotingWork : MarshalByRefObject
    {
        public void test()
        {
            int sum = 1;
            for (int i = 1; i <= 100; i++)
            {
                sum += i;
            }
            Atom.EventLog.Log.Write("sum=" + sum,"");
        }
    }

创建服务程序

View Code
[RunInstaller(true)]
    public partial class ProjectInstaller : System.Configuration.Install.Installer
    {
        public ProjectInstaller()
        {
            InitializeComponent();
            this.Committed += new InstallEventHandler(ProjectInstaller_Committed);//注册事件服务安装完成自动启动
        }

        private void ProjectInstaller_Committed(object sender, InstallEventArgs e)
        {
            System.ServiceProcess.ServiceController controller = new System.ServiceProcess.ServiceController("VAV_TL");
            controller.Start();
        }
    }

VAV_TL service,VAV_TL为服务名称

View Code
public partial class VAV_TL : ServiceBase
    {
        public VAV_TL()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            RemotingService.RemotingServer.GetInstance().Start();
            
        }

        protected override void OnStop()
        {
        }
    }

 

posted @ 2012-05-09 13:40  石 磊  阅读(292)  评论(0编辑  收藏  举报