Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Microsoft C# Professional Projects - Premier Press.pdf
Скачиваний:
177
Добавлен:
24.05.2014
Размер:
14.65 Mб
Скачать

826

Part IX

BEYOND THE LABS

 

 

 

Creating a Queue

The following steps explain how to create a message queue on your computer using the MessageQueue component. Using the MessageQueue component, you can send messages and retrieve them from the queue.

1.On the File menu, point to New, and then click Project.

2.In the New Project dialog box, choose Visual C# in the left pane, and Windows Application from the Template: pane.

3.Type the name of the application in the Name: text box and the desired location in the Location: text box.

4.Click the OK button.

5.Open Server Explorer.

6.Expand the Ser vers node.

7.Expand the node for your local server. The node on your local computer is identified by the computer name.

8.Expand the Message Queues node.

9.Right-click Private Queues and select Create Queue from the shortcut menu.

10.Enter a queue name, such as Trial. Do not check Make Transactional. A new private queue is created and appears in Server Explorer.

11.Drag the Trial queue from the Server Explorer onto your form. A new MessageQueue component is added to the project.

The MessageQueue component is used to programmatically access the messages contained in the Trial queue created earlier.

Summary

COM is a specification and implementation framework pioneered by Microsoft that allows you to create binary compatible software components. COM allows you to concentrate on developing your application without bothering about the internals of the components. COM architecture provides various threading models, which enables you to create components that are inherently thread savvy.

ADVANCED C# CONCEPTS

Chapter 34

827

 

 

 

 

MTS is an add-on to Windows NT that allows developers to build and run their components as middle tier. COM+ is the new run time in Windows 2000 that unifies the COM and MTS programming models. COM+ components support attribute programming, distributed transactions, synchronization, thread pooling and other features supported by the COM model. In addition, COM+ provides new features such as neutral apartment threading, queued components, role-based security, JIT activation, automatic transactions, and a new COM+ event model.

C# provides full support for COM+ services. Through COM interoperability, a C# program can call methods of any COM component.The process making this happen involves early and late binding. A .NET component may also be exposed as a COM component. The C# component does not need anything special to be written in the code. However, you can use type library importer utility to register a C# component and create a type library.

Message queuing is a technology that allows applications running at different times to communicate across heterogeneous networks and systems. Applications send, receive, or read messages from queues. The System.Messaging namespace provides classes that allow you to connect to, monitor, and administer message queues on the network and send or receive messages. The MessageQueue class is a wrapper around message queuing. The MessageQueue class provides members for reading and writing messages to the queue.

Messages are sent to and received from a queue as separate processes. Therefore, queue communication is inherently asynchronous. In synchronous communication, the sender of a request waits for a response from the receiver before performing other tasks.

This page intentionally left blank

 

 

Y

 

L

 

F

 

M

 

A

 

E

 

T

 

 

Team-Fly®

PART X

Appendixes

This page intentionally left blank

Appendix A

Unsafe Code