I am writing a worker service in Net core 6 and I want to call the worker service from API and pass sone data to worker service.
My Worker service code is as below:
``
IHost host = Host.CreateDefaultBuilder(args)
.UseWindowsService(options =>
{
options.ServiceName = "TestWindowService";
})
.ConfigureServices(services =>
{
services.AddHostedService<ServiceWorker>();
services.AddTransient<ITestService, TestService>();
services.AddTransient<IDatabaseClientService, DatabaseClientService>();
})
.Build();
await host.RunAsync();
``
I am calling Worker service from API and want to pass some data to Worker Service:
I tried this code from API but it is not working:
``
ServiceController service = new ServiceController();
service.MachineName = ".";
service.ServiceName = this.WindowServiceName;
if (service.Status != ServiceControllerStatus.Running)
service.Start(new string[] { "Testargs" });
`` How can I pass data from API to worker service? I tried the above code, but it is not working. Once the service is running then I want to pass data to it again.