IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddHostedService<Worker1>();
services.AddHostedService<Worker2>();
})
.Build();
await host.RunAsync();
In VS2022, inside Program.cs(the above is its whole content), I couldn't even declare the gloabal static variables (to be shared and updated by the two Worker), how to do that so that I can use Locks to sync updates between the two Workers. Any help will be appreciated.
It's resolved based on @AndrewSilver suggestions, put shared variable in a separate file:
Program:
Worker1: increment both I and J
Work2: decrement both I and J
Worker3:read only and watch for data inconsitence