Ensure foreground context is current on the main thread

Background must be non-current, otherwise it will raise error 170
(resource is in use) on the next MakeCurrent() call.
Merge pull request #2477 from thefiddler/fix2474

Ensure foreground context is current on the main thread