Acts 16: 22-34 recounts the scourging and imprisonment of Paul and Silas. I believe that this "unfortunate" occurrence could have been prevented; The Lord could have just whisked them away, just as He did for Philip, or He could have frozen time and let them out of the jail just like He did for Peter. However, this was not the case. He allowed His servants to be flogged and dumped in a jail for doing what He had sent them to do!!
As depressing as the situation may be, Paul and Silas prayed and sang hymns to God. Despite all of these, the ending of this account showed us the purpose of all this suffering - souls were saved. Through Paul and Silas' pain, the jailer, together with his whole household (of which a number was not stated), were brought to know the Lord. A soul is indeed priceless.
We have complained and sobbed over our presumed "predicaments" for too long. God sees and has a purpose/reason for allowing it to occur. Like Paul and Silas let us "pray and sing hymns" in the expectation of the fulfillment of God's perfect plan. This time around, it might be the salvation of a city or nation or the strengthening and deepening of our faith and dependance on Him.