Пример #1
0
 public int RemainingTimeInMilliseconds()
 {
     return(TimeoutHelper.ToMilliseconds(this.RemainingTime()));
 }
Пример #2
0
 public void SetTimer(TimerCallback callback, Object state)
 {
     Timer timer = new Timer(callback, state, TimeoutHelper.ToMilliseconds(this.RemainingTime()), Timeout.Infinite);
 }
Пример #3
0
        internal static ServiceInfo GetServiceInfo(string serviceName, TimeSpan timeout, SqlConnection con)
        {
            TimeoutHelper helper=new TimeoutHelper(timeout);
            ServiceInfo info = null;
            string SQL = @"
                select
                  s.name As ServiceName
                , s.service_id As ServiceId
                , q.name As QueueName
                , q.object_id As QueueId
                from sys.services s
                inner join sys.service_queues q
                  on s.service_queue_id=q.object_id
                where s.name=@ServiceName";

            SqlCommand cmd = new SqlCommand(SQL, con);
            cmd.Parameters.Add("@ServiceName", SqlDbType.VarChar).Value = serviceName;
            cmd.CommandTimeout = helper.RemainingTimeInMillisecondsOrZero();

            try
            {
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    if (!rdr.Read())
                    {
                        throw new CommunicationException(string.Format("Service {0} not found", serviceName));
                    }

                    info = new ServiceInfo();
                    info.ServiceName = rdr.GetString(0);
                    info.ServiceId = rdr.GetInt32(1);
                    info.QueueName = rdr.GetString(2);
                    info.QueueId = rdr.GetInt32(3);

                    rdr.Close();
                }
            }
            catch (SqlException ex)
            {
                if (!helper.IsTimeRemaining)
                {
                    throw new TimeoutException(String.Format("Timed out while getting service information. Timeout value was {0} seconds",timeout.TotalSeconds),ex);

                }
                else
                {
                    throw new CommunicationException("An exception occurred while getting service information", ex);
                }
            }

            return info;
        }