public Driver GetConnection()
{
int fullTimeOut = (int)settings.ConnectionTimeout * 1000;
int timeOut = fullTimeOut;
DateTime start = DateTime.Now;
while (timeOut > 0)
{
Driver driver = TryToGetDriver();
if (driver != null) return driver;
// We have no tickets right now, lets wait for one.
if (!autoEvent.WaitOne(timeOut, false)) break;
timeOut = fullTimeOut - (int)DateTime.Now.Subtract(start).TotalMilliseconds;
}
throw new MySqlException(Resources.TimeoutGettingConnection);
}