ServiceMode

From ESS-WIKI
Revision as of 05:39, 6 September 2018 by Luke.su (talk | contribs) (Created page with "C# code Service Mode class ServiceProgram : ServiceBase<br/>    {         public ServiceProgram()<br/>        {<br/> ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

C# code Service Mode

class ServiceProgram : ServiceBase
    {

        public ServiceProgram()
        {
            InitializeComponent();
        }

        //private BackgroundWorker client_worker = null;
        protected override void OnStart (string[] args)
        {
            Program.Client_main();
            Program.WriteLog("Start");

        }

        void client_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            try
            {
                //Program.Client_main();
            }
            catch (Exception err )
            {
                Program.WriteLog("[error] " + err.Message + err.StackTrace);
            }

            if (worker.CancellationPending)
                return;

        }

        public void Start(string[] args)
        {
            this.OnStart(args);
        }

        protected override void OnStop()
        {
            Program.Disconnect();
            Program.WriteLog("Stop");

        }

        public void Stop()
        {
            this.OnStop();
        }

        private void InitializeComponent()
        {
            this.ServiceName = "OpcuaClient";

        }
    }