This chapter marks a decisive change in the book in that it not only becomes much more positive than it has been preceding this, but it also becomes more exhortive.
Remember that the term qoheleth means "the lecturer" or "the preacher." The preacher is now calling on the people who are listening to his dissertation to make a decision. He does not say, "You can make any kind of decision you want," but he weighs his advice heavily in one direction. He says, "I want you to make a decision, but this is the decision I think you ought to make."
It becomes positive in its tone and exhortive in terms of making a decision as to what they should do with the knowledge that he has given them thus far. He strongly urges his readers or hearers to cast their lots with God.
This section begins in Ecclesiastes 11:1 and ends in 12:7. There is a sustained theme of exhortation to hold wholeheartedly to the faith and to decisive commitment to obedience to God, regardless of whether life is adverse or comfortable.
Remember that at the beginning of the book he said that life is frustrating. If God is involved in a person's life, he has the opportunity to remove a great deal of the frustration from his life. His relationship with God will take the meaninglessness, the vanity, out of life. But all the children of God are required to make that choice because both choices are still there.
Not only that, but we know from earlier in the book that the life of the person who is living by faith will also be filled with many of the same kind of adversities that those living in vanity are. He has to live with the understanding that many things are out of his control.
The Christian therefore has to deal with this, and the way this is done is to make a decisive commitment to cast his lot to live by faith. If he does that, then Romans 8:28 will be fulfilled in his life. The difficulties will be there, but because the Christian has involved God in the way that he lives his life, then all things will indeed work together for good to those who are the elect and who love God.