How to enforce required command-line options with NDesk.Options?

The problem is that documentation isn’t as clear as it apparently needs to be. 🙁 Specifically, as per: http://www.ndesk.org/doc/ndesk-options/NDesk.Options/OptionValueType.html#F:NDesk.Options.OptionValueType.Required The = within an option specification doesn’t apply to the OptionSet as a whole, but just to the value for that specific option. The importance of this is really only relevant in two scenarios, so first … Read more

How to receive Plug & Play device notifications without a windows form

You’ll need a window, there’s no way around that. Here’s a sample implementation. Implement an event handler for the DeviceChangeNotifier.DeviceNotify event to get notifications. Call the DeviceChangeNotifier.Start() method at the start of your program. Call DeviceChangeNotifier.Stop() at the end of your program. Beware that the DeviceNotify event is raised on a background thread, be sure … Read more

How to programmatic disable C# Console Application’s Quick Edit mode?

For those like me that like no-brainer code to copy/paste, here is the code inspired from the accepted answer: using System; using System.Runtime.InteropServices; static class DisableConsoleQuickEdit { const uint ENABLE_QUICK_EDIT = 0x0040; // STD_INPUT_HANDLE (DWORD): -10 is the standard input device. const int STD_INPUT_HANDLE = -10; [DllImport(“kernel32.dll”, SetLastError = true)] static extern IntPtr GetStdHandle(int nStdHandle); … Read more

The “correct” way to create a .NET Core console app without background services

Instead of a hosted service, I would recommend the following; using (var host = CreateHostBuilder(args).Build()) { await host.StartAsync(); var lifetime = host.Services.GetRequiredService<IHostApplicationLifetime>(); // do work here / get your work service … lifetime.StopApplication(); await host.WaitForShutdownAsync(); }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)