HaKadosh Baruch Hu established a law in Creation, that when we awaken in the world below to approach the Almighty and request a blessing from Him, He, in turn, is aroused from above to bring upon us an abundance of good, according to our needs and the requirements of the world. This is mentioned in the Zohar HaKadosh in many places.
In other words, even when people are worthy that Hashem shower them with goodness, sometimes the giving is delayed until they feel the weight of their hardships and pray to Hashem from the depths of their hearts.
There are two types of prayer.
The first is for the continual existence of the world; without prayer, the world would cease to exist. This kind of prayer parallels the Tamid sacrifice, the merit of which sustains the heavens and the earth (see Ta’anit 27b).
The second type of prayer concerns specific circumstances, such as when disaster strikes and people pray for salvation, or when people pray for something they desire.
Every prayer has an influential effect, as Rabbi Chanina says, “Whoever lengthens his prayer, his prayers do not return unanswered” (Berachot 32b). Sometimes the effect is immediate, and other times in the distant future; sometimes the prayer is answered completely, other times partially. As Chazal say (Devarim Rabbah 8:1), “Great is prayer before HaKadosh Baruch Hu. Rabbi Elazar says, If you want to know the power of prayer – if it does not accomplish everything, it achieves half.” HaKadosh Baruch Hu is the One Who knows how to help and support a person. Sometimes, for various reasons, a person’s misfortune is for his own good, and therefore Hashem does not accept his prayer. Nevertheless, his prayer benefits him, and its blessing will be revealed in one way or another.
Even the most righteous people, whose prayers were generally accepted, sometimes went unanswered. For instance, even though Hashem accepted Moshe Rabbeinu’s prayers to forgive the Nation and annul His decree of destruction when Israel sinned by creating the Golden Calf and sending out spies who returned with a negative report about the Land of Israel, (Exodus 32 and Numbers 14) when Moshe came to beg on behalf of himself to merit entering the Land, HaKadosh Baruch Hu said to him, “Enough! Do not talk to me further about this matter” (Deuteronomy 3:26).
Therefore, a person must exert himself greatly in prayer, and not assume that since he is praying, HaKadosh Baruch Hu must fulfill his request. Rather, he should continue praying, knowing that HaKadosh Baruch Hu hears his prayers and that his prayers are most certainly doing some good, although how much, and in what way, are unknown.