it may work
Hi - I think the absolute necessary thing for you is to have an employement with similar job duty 'at the time of' I-485 approval.
Folks in different forums have their theories on what kind of freedom one has while the I-485 is pending for more than 180 days.
My bit conservative take away based on that is - work in the companies C, D,.. that have similar job duties (and at least the salary as was in your labor), and once you get the I-485 approval, join company B in ~6 months (post approval).
If the companies C, D, etc do not offer the similar job duties, then your situation is more complicated than what I know. May be couple of gurus in this forum can shed some light on this to help you out ?