Romoting 第一个例子
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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,""); } }
创建服务程序
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[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为服务名称
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public partial class VAV_TL : ServiceBase { public VAV_TL() { InitializeComponent(); } protected override void OnStart(string[] args) { RemotingService.RemotingServer.GetInstance().Start(); } protected override void OnStop() { } }