/// <summary> /// Count the messages on the queue and return a formated count and time. /// </summary> /// <param name="queuename"></param> /// <param name="countMode"></param> /// <returns></returns> private static string BuildCount(string queuename, QueueCount.eCountMode countMode) { try { QueueCount qc = new QueueCount(queuename) {CountMode = countMode}; DateTime dtStart = DateTime.Now; int count = qc.Count(); DateTime dtEnd = DateTime.Now; qc = null; TimeSpan ts = dtEnd.Subtract(dtStart); string sReturn = string.Format("{0} : {1}ms", count.ToString("#,##0"), ts.TotalMilliseconds.ToString("#,##0")); //string sReturn = string.Format("{0} : {1}ms", // count.ToString("#,##0").PadLeft(8), // ts.TotalMilliseconds.ToString("#,##0").PadLeft(6)); return sReturn; } catch (Exception) { return "Error"; } }
/// <summary> /// Count the number of messages in the message queue /// </summary> /// <returns></returns> public int? Count() { if (_MessageQueue == null) return null; int? iReturn = 0; var qc = new QueueCount(_MessageQueue); iReturn = qc.Count(); return iReturn; }