none
Getting started with WCF RRS feed

  • Question

  • I have been trying to find out how to make a WCF application that will constantly do some task but without being hard on a computer. How can I achieve that with WCF?

    Microsoft Student Parnter Microsoft Technology Associate

    • Moved by Bob Shen Tuesday, June 11, 2013 1:27 AM
    Sunday, June 9, 2013 11:40 PM

Answers

  • Hi,

    You said that you have wcf application that will constantly do some task, then do you mean that you want to schedule a wcf service. 

    In order do this, we should call the WCF service method from some kind of task scheduler. Or there is a really simple form, you could just spawn a Thread from your service, that runs the WCF method periodically like the below. 

    [ServiceContract]
    public class SomeClass
    {
        [ServiceOperation]
        public void SomeServiceMethod() { ... }
    Then somewhere in the application startup:
    
    Thread t = new Thread(new ThreadStart(CallService));
    t.Start();
    
    .........
    
    // this will call the WCF service method once every hour
    public void CallService()
    {
        Thread.Sleep(3600000); // sleep 1 hour
        new SomeClass().SomeServiceMethod();
    }

    The following thread is similar to you, please try to refer to:
    http://stackoverflow.com/questions/789852/wcf-windows-service-as-scheduled-service .

    Here is tutorial about get starting with the WCF:
    http://msdn.microsoft.com/en-us/library/ee354180.aspx .

    Hope it can help you.

    Best Regards.


    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Tonchi91 Thursday, June 13, 2013 8:43 PM
    Tuesday, June 11, 2013 2:04 AM
    Moderator

All replies

  • Hi TonchiVZ,

    I would like to redirect you to appropriate forum for better responses.


    Bob Shen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, June 11, 2013 1:27 AM
  • Hi,

    You said that you have wcf application that will constantly do some task, then do you mean that you want to schedule a wcf service. 

    In order do this, we should call the WCF service method from some kind of task scheduler. Or there is a really simple form, you could just spawn a Thread from your service, that runs the WCF method periodically like the below. 

    [ServiceContract]
    public class SomeClass
    {
        [ServiceOperation]
        public void SomeServiceMethod() { ... }
    Then somewhere in the application startup:
    
    Thread t = new Thread(new ThreadStart(CallService));
    t.Start();
    
    .........
    
    // this will call the WCF service method once every hour
    public void CallService()
    {
        Thread.Sleep(3600000); // sleep 1 hour
        new SomeClass().SomeServiceMethod();
    }

    The following thread is similar to you, please try to refer to:
    http://stackoverflow.com/questions/789852/wcf-windows-service-as-scheduled-service .

    Here is tutorial about get starting with the WCF:
    http://msdn.microsoft.com/en-us/library/ee354180.aspx .

    Hope it can help you.

    Best Regards.


    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Tonchi91 Thursday, June 13, 2013 8:43 PM
    Tuesday, June 11, 2013 2:04 AM
    Moderator