123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.ServiceProcess;
- using System.Text;
- using System.Threading;
- using System.Runtime.InteropServices;
- namespace US.Browser.Service
- {
- partial class USservice : ServiceBase
- {
- //线程对象
- Thread _TestForm = null;
- System.Timers.Timer timer = null;
- public USservice()
- {
- InitializeComponent();
- timer = new System.Timers.Timer();
- timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
- timer.Interval = 10000;
- }
- void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- //定义 启动线程
- _TestForm = new Thread(new ThreadStart(StartListen));
- _TestForm.Start();
- }
- protected override void OnStart(string[] args)
- {
- // TODO: 在此处添加代码以启动服务。
- //判断当前系统是否为win7
- if (!(Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows NT\\CurrentVersion").GetValue("ProductName").ToString().IndexOf("Windows 7") > -1))
- {
- //timer.Start();
- _TestForm = new Thread(new ThreadStart(StartListen));
- _TestForm.Start();
- }
-
- }
- protected override void OnStop()
- {
- // TODO: 在此处添加代码以执行停止服务所需的关闭操作。
- timer.Stop();
- }
- public void StartListen()
- {
- ServerWindows.ServiceForm(EventLog);
- Message tmp = new Message();
- tmp.Left = System.Windows.Forms.Screen.GetWorkingArea(tmp).Width-tmp.Width;
- tmp.Top = System.Windows.Forms.Screen.GetWorkingArea(tmp).Height - tmp.Height;
- //显示窗体的代码
- System.Windows.Forms.Application.Run(tmp);
- while (true)
- {
- Thread.Sleep(100000);
- }
- }
- }
- }
|