本文介绍了如何启动Windows服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.....

我已经开发了一个Windows服务,它正在开始。但是我在下面的代码中遇到了问题



Hi....
I have developed a windows service and it is getting start.But i have a problem in the below code

protected override void OnStart(string[] args)
    {
        string strBody = "Hello";
        string strSubject = "test";
        //conn.Close();

        //string subjectTo = "this is a sample message to check!!!!!";
        SendEmail(strSubject, strBody, "****.com", "*****.com", "****8.com", "");

        eventLog1.WriteEntry("In OnStart");
        FileStream fs = new FileStream(@"c:\temp\mcWindowsService.txt",
        FileMode.OpenOrCreate, FileAccess.Write);
        StreamWriter m_streamWriter = new StreamWriter(fs);
        m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
        m_streamWriter.WriteLine(" mcWindowsService: Service Started \n" + DateTime.Now);
        m_streamWriter.Flush();
        m_streamWriter.Close();
    }



这是我的窗口服务的OnStart功能...在这里我写了一个邮件功能,但我没有得到所需的输出...你可以帮助我plzzzz


This is my OnStart function of my window service...In this i have written a mail function but i am not getting required output...can u help me plzzzz

推荐答案

try{
        string strBody = "Hello";
        string strSubject = "test";
        //conn.Close();

        //string subjectTo = "this is a sample message to check!!!!!";
        SendEmail(strSubject, strBody, "****.com", "*****.com", "****8.com", "");

        eventLog1.WriteEntry("In OnStart");
        FileStream fs = new FileStream(@"c:\temp\mcWindowsService.txt",
        FileMode.OpenOrCreate, FileAccess.Write);
        StreamWriter m_streamWriter = new StreamWriter(fs);
        m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
        m_streamWriter.WriteLine(" mcWindowsService: Service Started \n" + DateTime.Now);
        m_streamWriter.Flush();
        m_streamWriter.Close();
}
catch(Exception ex)
{
    System.IO.File.WriteAllText(@"c:\error.txt",ex.ToString());
}



看看错误是什么。


And see what the error is.


这篇关于如何启动Windows服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 20:10