This procedure is very handy if you want to control the load on a mirrored database. For example rebuilding indexes on the principal database generates a lot of load on the mirrored database (especially with a snapshot).
In order to control the load on a mirrored server, create this procedure (on the principal) and insert a call to this procedure between each "heavy" (statement on the principal).
For example, I rebuild my indexes by a cursor loop and just before I fetch the next index, I call this procedure. This procedure takes the mirror tresholds from SQL. NOTE: By using this procedure, you still might get messages in your errorlog about mirror tresholds. This procedure only slows down your statements (in order to give the mirrored database more breath).
In order to prevent an infinite execution of this statement, @MaxWaitSeconds determines the number of seconds before this procedure aborts (a returncode is set).
@Checkdelay is the delaytime before the tresholds are checked again.