1

I am starting using an external library (SDK) that requires a context(SynchronizationContext) at initialization, so my first approach on testing it was by writing a simple console app, but, when I try to use SynchronizationContext.Current is null.

string key = ConfigurationManager.AppSettings[Constants.KEY];

if (DLL.Init(key, SynchronizationContext.Current))
{
  Console.WriteLine($"{DLL.IsInitialized()} Press enter to close...");
  Console.ReadLine();
}
Console.WriteLine($"{DLL.IsInitialized()} Press enter to close...");
Console.ReadLine();

Would you mind helping me to understand the usage of ``SynchronizationContext``` and why is not initialized at the console app?

Update This question could be similar to -> Why the default SynchronizationContext is not captured in a Console App?, but, I do not understand, why a console app needs a custom context?

judicapo
  • 45
  • 4
  • 2
    Please check out this blog post regarding `SynchronizationContext` in console application: https://veganhunter.net/2016/12/02/synchronizationcontext-in-console-applications/ – IceCode May 08 '19 at 07:55
  • 1
    "I do not understand, why a console app needs a custom context" Because it doesn't have a WPF or WF maintained synchronization context. – Patrick Hofman May 08 '19 at 08:40
  • Any suggestions of how and where SynchronizationContext is implemented and used for? thanks – judicapo May 08 '19 at 10:25

0 Answers0