Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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();
    }
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
Posted 11-Feb-13 19:23pm
Edited 11-Feb-13 19:35pm
SoMad105.5K
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try :
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.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Dnyaneshwar@Pune 1,310
1 Sergey Alexandrovich Kryukov 1,001
2 OriginalGriff 303
3 Tadit Dash 290
4 Manas Bhardwaj 215
0 Sergey Alexandrovich Kryukov 11,441
1 OriginalGriff 6,930
2 Peter Leow 4,850
3 Abhinav S 3,838
4 Maciej Los 3,575


Advertise | Privacy | Mobile
Web03 | 2.8.140421.2 | Last Updated 12 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid