ho0ber / NK2Tray

Windows Application Volume Control via MIDI
Microsoft Public License
167 stars 26 forks source link

Fixing race condition. #101

Closed nathanojb closed 3 years ago

nathanojb commented 3 years ago

Ran into this after I upgraded my pc.

Fixing it here in the simplest way. Maybe not the best solution, but I'm not familiar with windows forms.

Through trial and error it seem like _workerDispatcher = Dispatcher.CurrentDispatcher; Dispatcher.Run();

...must be set in _workerThread, otherwise the gui doesn't work or the program won't exit cleanly. On faster machines we race to Invoke(SetupDevice); before _workerThread has instantiated the _workerDispatcher

easy way to solve is to just wait here until _workerDispatcher is set.

I see on discord that this is a common error. Maybe it's a scheduling thing on certain cpu's? Exception it causes otherwise:

System.NullReferenceException: Object reference not set to an instance of an object. at NK2Tray.SysTrayApp.ctor() at NK2Tray.SysTrayApp.Main()