You are sleeping and in your dream a snake comes and bites you and you wake up screaming!
So, there are a few things even in a dream that can become the reason for you waking up from the dream.
That is why it is said, 'neki kar aur kuye mein daal' - do good deeds and forget about them as though they are also a part of the dream. When you drop those deeds and meditate, then you will awaken.
There are two aspects of sadhana: nishreya and abhyudaya. One is awakening and the other is comfort.
Sadhana brings that comfort which one longs for and freedom is attained by it. We awaken from the dream and come out of it by doing sadhana.