this has to be really fast depending of your software and crystal speed

did you try something like this right at the top of your code

TRISB =0
Solenoid var PORTB.0
solenoid=0