I have a program written in c# and want it to start when my instance start.
I already added "mono /home/ec2-user/program/program.exe" to /etc/rc.local but it does nothing. What do I have to do?
Consider using cloud-init (if you are using Ubuntu), or a user-data start script. These will allow you to start an instance, configure it how you like (with necessary packages like mono), download your own code, and have it run as soon as the instance starts.
This is a preferred way to re-using instances or repackaging instances since all the steps needed to transform a 'stock' image to your own customized one is automated.
ec2-run-instance boots up a fresh instance. ec2-start-instance resumes an existing (but stopped) instance at whatever point the instance was at when it was stopped. While there's lots of ways of getting instances to do things when they first boot, there aren't so many ways to get instances to do things when they are started. Consider writing your code as a daemon that always runs, then it will be stopped and started with the instance as you expect.@vsekhar is correct, as far as I am aware, regarding what happens when the instance is restarted. In that case, a daemon is about the best that can be done.
However, as all information in RAM is lost, it is often okay to just reboot. You can start the instance and reboot, allowing for normal processing of startup scripts. For rebooting, you can use ec2-reboot-instances.