Well, in most cases yes, you should be able to do it
If certain conditions are met, then you can begin working for Company B once that employer's H-1B petition has been received by USCIS. Check with Company B's immigration attorney to ensure you meet the requirements for doing so.