Hi,
I have a console application scheduled on windows server but when the task start the window console appear.
So i ha ve two ways:
1-hide the console windows
2-create a windows service
I prefer the second option so in in net core 6 which is the best practice to do that?
My program.cs is this:
using MyConsoleApp.Contexts;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace MyConsoleApp
{
public class Program
{
static void Main(string[] args)
{
using (var dbContext = new DataContext())
{
var dwhservice = new MyDataService(dbContext);
dwhservice.CopyRecords();
}
}
#region property
public IConfiguration Configuration { get; }
public Program(IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("DataConnection"), o => o.CommandTimeout(600)));
}
#endregion
}
}
Thanks
Mayooran NavamanyPosted Jul 12, 2023, 6:30 AM
Hi Mic
This article introduces Windows Services in .NET and how to create a Windows Service in C# and .NET using Visual Studio. It's useful for you.
https://www.c-sharpcorner.com/article/create-windows-services-in-c-sharp/
Mudzakkir TohaPosted Jul 11, 2023, 10:46 PM
The answer is depend on your ability.
I prefer use option 1, because I am familiar with console app.
I do not know about You.
If you are in hurry, choose the most familiar tech stack.
If you want to do self research, try google it before you ask to community.