Click here to Skip to main content
16,019,206 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i need to call a method in windows service which have a timer to schedule some task .How will I call that method in a console application or asp.net application

What I have tried:

i need to call a method in windows service which have a timer to schedule some task .How will I call that method in a console application or asp.net application
Posted
Updated 5-Nov-19 20:41pm

I'm not sure I know what you're looking for ... you can :-

a) send a 'Custom command' to a Windows Service Program using ServiceController.ExecuteCommand

const int DoSomething = 666;

service.ExecuteCommand(DoSomething);
service.WaitForStatus(ServiceControllerStatus.Running, timeout);


This can be done in an external eg Console mode program. The Service implements/overrides ServiceBase.OnCustomCommand to react ..

C#
protected override void OnCustomCommand(int command)
{
    if (command == DoSomething)
    {
        // ...
    }
}


b) have a 'receiver' (named pipes, tcp/ip) in your service that receives a 'message' from an external source and does something like process a 'task'

c) you can have a Service built with Quartz.Net for example that runs 'tasks', by using all sorts of scheduling specs, eg cron type specs

but, as you have written it, no, you cannot 'call a method in windows service' - maybe you need to update your question and refine your requirements a touch more
 
Share this answer
 
v3
Comments
OmGanesh 15-May-17 14:02pm    
@Garth,
I have the same issue as I need to run the long-running task in background on user's request from asp.net MVC web application.
I am completely lost by abundant articles in web with options (Quartz, Hangfire, Named Pipes, Azure Jobs, ...). I thought windows services as my best solution as the existing project is already having one windows services running every 4 hours.

My requirement is to create another listener/method (whatever we call it) where I can send message from my web application on users' request. This method will basically perform the actions based on the DB table (the real task will be done based on table flag) so I just need to give order to my service method to check the db entry to perform new task)

Note: Requirement is there can be simultaneous call to the service from different web users at same time.

Your comment and/or reference articles will be highly appreciated !!!
using (ServiceReference1.WebServiceSoapClient WS = new ServiceReference1.WebServiceSoapClient())
{
DataTable Result = WS.Get();
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900