If you are using Gadgeteer (which is where program.generated comes from) you must NOT use a thread.sleep(timeout.forever) (or a while(true) loop) in the ProgramStarted().
Basically, “sleep forever” stops a netmf app from “terminating”. If you think about what netmf devices were originally (or are still) meant to do, they’re meant to run forever doing the same thing, so the apps should never “end”; the thread.sleep means that the thread stays alive but asleep. So that’s why other examples use the sleep, or a while(true) loop.
In Gadgeteer, there is a layer on top of the netmf that manages it’s own dispatcher, and therefore never sleeps.