Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Help with creating a Windows Service (C#)

  • 11-03-2007 8:54pm
    #1
    Registered Users, Registered Users 2 Posts: 872 ✭✭✭


    Hi,

    I need to make a windows service that checks a folder on the local system to see if there are any XML files in it. The check needs to be done every 15 minutes.

    If there are files i loop through all the files in the folder and do what i need to do with them.

    Should i use System.Threading.Sleep to perform the wait interval between checks ?

    Also, does anyone know any good resources for creating windows services

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 38 noonand


    Hello,

    Just going to give you enough to get you started here:
    protected override void OnStart(string[] args)
    {
    Thread xmlProcessingThread = new Thread(new ThreadStart(ProcessXmlFiles));
    xmlProcessingThread.Start();
    }
    
    private void ProcessXmlFiles()
    {
    while(true)
    {
    
    // Process your files here
    // ...
    
    
    // And at the end call this...
    Thread.Sleep(TimeSpan.FromMinutes(15));
    }
    }
    

    You may want to consider making the time interval configurable (i.e. in the app.config) - I'll leave this as an excercise to you.

    There's no indentation to speak of as it looked awful in the text box window but I'm sure you'll figure it out. Also there may be minor syntactical errors here but the concept is sound. This code has not been tested and may sprout hairy things when compiled. Your kilometreage may vary, yada, yada.

    ATB,
    Derek

    "It's all fun and games till someone loses an eye..."


  • Registered Users, Registered Users 2 Posts: 38 noonand


    grahamor wrote:
    Also, does anyone know any good resources for creating windows services

    Just spotted this - without being facetious - in Visual Studio 2005 choose File > New > Project

    Assuming Visual C#, select the Windows category and pick 'Windows Service' from the right hand side.

    That will set up a complete skeleton for you with all the stubs you need.

    ATB,
    Derek

    "It's all fun and games till someone loses an eye..."


  • Registered Users, Registered Users 2 Posts: 2,300 ✭✭✭PixelTrawler


    If you can get your hands on the exam book for MCPD 70-536
    "MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework 2.0—Application Development Foundation"
    , there is a very useful chapter on creating a basic webservice, including building the installer file for setting it up. It also shows how to hook up the start, stop, pause actions for use in the services.msc console.

    Check out Lesson8, Exercise3, Page 457


Advertisement