15.02.2015 Views

C# 4 and .NET 4

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Course order application ❘ 1373<br />

}<br />

message.Recoverable = true;<br />

queue.Send(message, String.Format("Course Order {{{0}}}",<br />

order.Customer.Company));<br />

}<br />

MessageBox.Show("Course Order submitted");<br />

}<br />

catch (MessageQueueException ex)<br />

{<br />

MessageBox.Show(ex.Message, "Course Order Error",<br />

MessageBoxButton.OK, MessageBoxImage.Error);<br />

}<br />

code snippet CourseOrderSender/CourseOrderWindow.xaml.cs<br />

By running the application, you can add course orders to the message queue (see Figure 46 - 11).<br />

figure 46-11 figure 46-12<br />

Course order message receiver<br />

The design view of the Course Order receiving application that reads messages from the queue is shown in<br />

Figure 46 - 12. This application displays labels of every order in the listOrders list box. When an order is<br />

selected, the content of the order is displayed with the controls on the right side of the application.<br />

In the constructor of the Window class CourseOrderReceiverWindow , the MessageQueue object is created<br />

that references the same queue that was used with the sending application. For reading messages, the<br />

XmlMessageFormatter with the types that are read is associated with the queue using the Formatter property.<br />

To display the available messages in the list, a new task is created that peeks at messages in the background.<br />

The task ’ s main method is PeekMessages .<br />

You can read more about tasks in Chapter 20.<br />

using System;<br />

using System.Messaging;<br />

using System.Threading;<br />

using System.Windows;<br />

using System.Windows.Controls;<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!