The structure of Sonnet 29 is very interesting. The first eight lines are a relative when-clause indicating the time of the occurrence detailed (or occurrences, depending on how you look at the string of reactions):
PARAPHRASE WHEN I in disgrace weep and cry and curse and wish to be someone with hope, looks or situation, friends, art, intelligence, contentment;....
The relative when-clause is followed by an introductory adverbial clause:
Yet in these thoughts myself almost despising,....
This "Yet" adverbial can be paraphrased for clarity this way: PARAPHRASE Even so, even with these thoughts that make me almost despise myself ....
This adverbial introduces a variation on a standard if-then conditional. The clauses comprising the conditional form a zero conditional representing a statement of simple fact. The simple present tense is used for both sides of the conditional: e.g., If something happens, then the result is something. As Shakespeare puts it:
Haply I think on thee, and then my state, / ... / sings hymns at heaven’s gate;
The import of the expression "Yet in these thoughts" is that Shakespeare presents the paradox that leads to the resolution of the problem in the sonnet. The problem in the sonnet is that the poetic persona nearly despises himself because, for one reason or another, things are going rather badly for him professionally at the moment: "in disgrace with fortune and men’s eyes...." The paradox presented is embodied in "Yet," which can be understood as the synonyms "even so," "nevertheless," "in spite of [that]."
What Shakespeare says in the one word "Yet" is that, even with all the woe the persona has described, in spite of all the failure he feels, paradoxically, something greater than all this can alter the course of his thoughts.
What is the the thing that is greater and how are his thoughts altered?
Line 10 identifies the something that is greater than all the speaker's gloomy, self-disparaging thoughts: "Haply I think on thee."
The something that greater is the person to whom the sonnet is address, the "thee" the very thought of whom can elevate the persona's mind from the dejection he feels. The thought of this "thee" raises the poetic speaker's psychological condition, like a lark on the wing at dawn, so that he feels like he is singing hymns at "heaven's gate."
The if-then element, present in a variation on the form, can be paraphrased as: IF I think on "thee," THEN my inner being rises up and sings hymns at "heaven's gate."
The summary of this sonnet can be presented as this brief PARAPHRASE: WHEN I am glum and despairing, comparing myself adversely against everyone, almost despising myself and what I love to do, IF I but think of "thee," THEN my soul soars and I feel like I'm in heaven singing.
The final two lines, lines 13 and 14--the ending couplet with rhyming end-words "brings" and "kings"--give the REASON ("For") and the CONSEQUENCE ("That then") that provide the resolution to the paradox and the problem.
The resolution of the sonnet is that thoughts of "thee" bring such a "wealth" of goodness that the speaker is no longer dissatisfied and would not even trade places with kings.
This is a "love conquers all" sonnet: The wonderful wealth of goodness thoughts of your love provide me with are greater than my problems and greater than the gold of kings.
Is the Sonnet Autobiographical?
One of the foremost theories about the nature of Shakespeare's sonnet cycle is that they are autobiographical. When trying to find an autobiographical explanation for the context of Sonnet 29, there are two events that would have affected Shakespeare and that happened around the time the sonnet was written.
The first is that theaters were closed because of the black plague sweeping through London. This incident--while it may have made Shakespeare despondent because he and all were blocked from the London stage--doesn't really seem to be in tune with the despair, dejection, sense of failure, sense of shame, humiliation and worthlessness evident in the when-clause.
The second incident is that a university educated playwright, who thought Shakespeare was an incompetent who dishonored the craft of play writing, published a scathing denunciation of Shakespeare. The consensus is that Shakespeare was rather shaken by Greene's vicious commentary. This is precisely the sort of incident Sonnet 29 harmonizes with and which would provoke the feelings expressed in the sonnet. Though all we can do is speculate, it seems sound to speculate that Sonnet 29 is a response to dramatist Robert Greene's 1592 scathing commentary (Amanda Mabillard, ShakespeareOnline):
"There is an upstart Crow, beautified with our feathers, that with his Tygers heart wrapt in a Players hide, supposes he is as well able to bombast out a blanke verse as the best of you; and, beeing an absolute Johannes factotum, is in his owne conceit the only Shakescene in a countrey." (Robert Greene, A Groats-Worth of Wit, 1592)