Am I Blessing God At All Times or Only When Something Good Happens?

I remembered the time I thought it's crazy to thank God all the time. I couldn't comprehend at it especially when I first read Psalm 34. The first verse made me think that it must be madness to thank God all the time even in times of trouble. The first verse struck me and it made me hate the Bible all the more before I got saved:
Psalm 34:1 - I will bless the LORD at all times: His praise shall continually be in my mouth.

I even thought it once to be lunacy. Nothing was more offensive for my sinful, unsaved self-reading that I should thank God for the bad times. Worse, I was reading the Book of Job and found out this verse:
Job 2:10 - But he said unto her, Thou speakest as one of the foolish women speaketh. What? Shall we receive good at the hand of God and shall we not receive evil? In all this did not Job sin with his lips. 

I soon embraced these verses when I received Jesus Christ as my Lord and Savior. But there are times I just find myself sinning by complaining why God allows such things to happen. Sometimes, I even feel like God allows bad things to happen to me because there's some self-righteousness that I need to deal with by His grace. It's because every time bad things happen I notice how often I want to say, "Lord why is this happening to me... I have been so good!" I have no right to say that considering that I have sinned in every little way that I haven't noticed.

So why should I thank God for the bad things that happen? There's one truth that men are more in danger of their worldly comfort zones than they are in their affliction. 
Psalm 119:71 - It is good for me that I have been afflicted; that I might learn Thy statutes.

David acknowledged it that it was through this affliction that He learned the statutes of God even more. I noticed how often that if my life has gone too easy it's very easy for me to brag and forget God. But God cares too much about His children and He knows the harm arrogance will bring to them. He has done everything to humble because He wants to work through His children.

I end up thinking of every act of bad thing as a chastisement for whatever secret sins I'm not aware of. It's a wake-up call, an invitation to prayer and I noticed how deep my devotion is on times of tribulation than in the times of comfort. I can go ahead and live a godly life but how sure am I'm not free from any secret sin? I can't say my thoughts were always pure and my heart is kept free from sin.
Proverbs 20:9 - Who can say that I have made my heart pure that I am pure from my sin?

I should be thankful for the bad times is because God is teaching me something. It's also all about keeping my priorities straight. Am I feeling too much at home with this world? Am I wasting whatever talent God has entrusted to me for myself? Am I being self-righteous like a Pharisee? Am I harboring an unforgiving spirit towards someone as of late? There's a lot of sins that I may be ignoring and God wants me to be back on track.

See also: