I beleive it is a swift action to perform, so you can only do it on your turn. If you use the ninja's ki ability to go invis, it lasts until the beginning of your next turn. So if you want to turn invis and attack, you can do so, and you will remain invis no matter if you are making 1 attack or 50...