We've been playing around with solenoid pulsing this year and Mark is right about the reaction time- Switching on/off for our Festo VUVG solenoid is 7ms/19ms. My understanding of it was that in order for the solenoid to turn on, you would have to send it a signal for at least 7ms, then once you stop sending the signal, it would take an additional 19ms to completely close.
In order to make the code run only once per button click you'd need to use rising edge detection. I'd refer to
this thread.
I'll see if I can find some code to post.