首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#做windows服务的有关问题

2012-01-24 
C#做windows服务的问题怎么才能让服务打开指定窗体??最好有示例。。。帮帮忙吧~~[解决办法]用服务也不难我做

C#做windows服务的问题
怎么才能让服务打开指定窗体??最好有示例。。。帮帮忙吧~~

[解决办法]
用服务也不难
我做的一个监控程序,调试的时候需要查看用系统事件日志

C# code
        public void MonitorProcess()        {            // Create the source, if it does not already exist.            if (!EventLog.SourceExists("MySource"))            {                EventLog.CreateEventSource("MySource", "MyNewLog");            }            EventLog myLog = new EventLog();            myLog.Source = "MySource";            List<String> CurrentSystemProcessList = new List<String>();            CurrentSystemProcessList.Clear();            Process[] localAll = Process.GetProcesses();            //EventLog myLog = new EventLog("ServiceTest", ".", "ServiceTest");            StringBuilder msg = new StringBuilder("");            for (int i = 0; i < localAll.Length; i++)            {                if (localAll[i].ProcessName == "Rever")                {                    //localAll[i].Close();                    try                    {                        bool IsCloseMainWindow = false;                        IsCloseMainWindow=localAll[i].CloseMainWindow();                        if(!IsCloseMainWindow)                        {                            msg.Remove(0, msg.Length);                            msg.Append(DateTime.Now.ToString());                            msg.Append(" 进程调用CloseMainWindow,没有成功!");                            myLog.WriteEntry(msg.ToString());                            localAll[i].Kill();                        }                        localAll[i].WaitForExit();                        //this.Stop();                        Process.Start(@"D:\Rever.exe");                        msg.Remove(0, msg.Length);                        msg.Append(DateTime.Now.ToString());                        msg.Append(" 程序执行成功!");                        myLog.WriteEntry(msg.ToString());                    }                    catch (Win32Exception ee)                    {                        msg.Remove(0, msg.Length);                        msg.Append(DateTime.Now.ToString());                        msg.Append(" 退出程序失败!");                        myLog.WriteEntry(msg.ToString());                    }                }            }                        }
[解决办法]
看看这篇文章
http://blog.joycode.com/chinahuman/archive/2008/05/04/115103.aspx

热点排行