public void Go() { _sb = new StringBuilder(); string queueName = GetPrivateQueueName(); InformUser( string.Format("Queue : {0}", queueName)); QueueWriter qw = new QueueWriter(queueName); qw.Purge(); string header = string.Empty; header += "Cursor".PadRight(_columnWidth); header += "GetAllMessages".PadRight(_columnWidth); header += "GetEnumerator2".PadRight(_columnWidth); if(CountUsingPowerShell) header += "PowerShell".PadRight(_columnWidth); InformUser(header); for (int i = 5000; i <= 100000; i += 5000) { Generate(i, queueName); CountMessagesOnQueue(queueName); } // write out the contents of the string builder. System.Diagnostics.Debug.Print(_sb.ToString()); }
/// <summary> /// Generate test messages /// </summary> /// <param name="messagesToGenerate">number of messages to generate</param> /// <param name="queueName">Which queue to write to</param> private static void Generate(int messagesToGenerate, string queueName) { string body = "It was the best of times, it was the worst of times ".PadRight(5000, 'q'); const string label = "MSMQ Count Speed Test Message"; //build the messages Message msg = new Message { Body = body, Label = label }; List<Message> messages = new List<Message>(); for (int i = 0; i < messagesToGenerate; i++) { messages.Add(msg); } // Write to the queue as a batch; QueueWriter qw = new QueueWriter(queueName); qw.Purge(); qw.SendMessage(messages); qw.Dispose(); }