I discovered an interesting issue while experimenting with Threading.
I have the following Main Program:
ToggleOutput is a simple class I made to toggle an output pin periodically. I tried 2 different methods to toggle:
Method 1 uses Thread.Sleep:
Method 2 uses an infinitely loop with a counter. The pin toggles every 3000 iterations:
If method 1 is used, everything works fine.
If method 2 is used, The onboard LED will flash for a second or so, then it will stop flashing, while my LEDs connected to A0 and A1 will continue to flash. The observation suggests the main thread will run for a second or so, then the scheduler will give execution cycles to thread 1 and 2, but the main thread was never given any processing cycle back to execute its operation. The workaround is creating a 3rd thread to flash the onboard LED, and in main, put Thread.CurrentThread.Suspend() to suspend the main thread.
Interestingly, if I run the program using method 2 through a debugger with Visual Studio, then everything works fine.
Full test program is attached.