Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net481</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Messaging" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,18 @@ public class QueueExample
{
public static void Main()
{
// Create a new instance of the class.
QueueExample example = new QueueExample();

// Create a nontransactional queue on the local computer.
CreateQueue(".\\exampleQueue", false);

example.UseQueue();
UseQueue();

return;
}

// Create a new queue.
public static void CreateQueue(string queuePath, bool transactional)
{
if(!MessageQueue.Exists(queuePath))
if (!MessageQueue.Exists(queuePath))
{
MessageQueue.Create(queuePath, transactional);
}
Expand All @@ -31,7 +28,7 @@ public static void CreateQueue(string queuePath, bool transactional)
}
}

public void UseQueue()
public static void UseQueue()
{
// <snippet1>
// Connect to a queue on the local computer. You must set the queue's
Expand Down
11 changes: 4 additions & 7 deletions snippets/csharp/System.Messaging/MessageQueue/.ctor/class11.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@
using System;
using System.Messaging;

public class QueueExample
public class QueueExample2
{
public static void Main()
{
// Create a new instance of the class.
QueueExample example = new QueueExample();

// Create a nontransactional queue on the local computer.
CreateQueue(".\\exampleQueue", false);

example.UseQueue();
UseQueue();

return;
}

// Create a new queue.
public static void CreateQueue(string queuePath, bool transactional)
{
if(!MessageQueue.Exists(queuePath))
if (!MessageQueue.Exists(queuePath))
{
MessageQueue.Create(queuePath, transactional);
}
Expand All @@ -31,7 +28,7 @@ public static void CreateQueue(string queuePath, bool transactional)
}
}

public void UseQueue()
public static void UseQueue()
{
// <snippet1>
// Connect to a queue on the local computer, grant exclusive read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace MyProject
/// </summary>
public class MyNewQueue
{

//**************************************************
// Provides an entry point into the application.
//
Expand All @@ -22,8 +21,8 @@ public static void Main()
// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue();

// Output the count of Lowest priority messages.
myNewQueue.GetExclusiveAccess();
// Output the count of Lowest priority messages.
GetExclusiveAccess();

return;
}
Expand All @@ -34,7 +33,7 @@ public static void Main()
// queue.
//**************************************************

public void GetExclusiveAccess()
public static void GetExclusiveAccess()
{
try
{
Expand Down Expand Up @@ -65,4 +64,4 @@ public void GetExclusiveAccess()
}
}
}
// </Snippet1>
// </Snippet1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net481</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<Reference Include="System.Messaging" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,59 @@

namespace MyProject
{
/// <summary>
/// Provides a container class for the example.
/// </summary>
public class MyNewQueue
{

//**************************************************
// Provides an entry point into the application.
//
// This example performs asynchronous peek operation
// processing.
//**************************************************

public static void Main()
{
// Create an instance of MessageQueue. Set its formatter.
MessageQueue myQueue = new MessageQueue(".\\myQueue");
myQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(String)});

// Add an event handler for the PeekCompleted event.
myQueue.PeekCompleted += new
PeekCompletedEventHandler(MyPeekCompleted);

// Begin the asynchronous peek operation.
myQueue.BeginPeek();

// Do other work on the current thread.

return;
}

//**************************************************
// Provides an event handler for the PeekCompleted
// event.
//**************************************************

private static void MyPeekCompleted(Object source,
PeekCompletedEventArgs asyncResult)
{
// Connect to the queue.
MessageQueue mq = (MessageQueue)source;

// End the asynchronous peek operation.
Message m = mq.EndPeek(asyncResult.AsyncResult);

// Display message information on the screen.
Console.WriteLine("Message: " + (string)m.Body);

// Restart the asynchronous peek operation.
mq.BeginPeek();

return;
}
}
/// <summary>
/// Provides a container class for the example.
/// </summary>
public class MyNewQueue
{
//**************************************************
// Provides an entry point into the application.
//
// This example performs asynchronous peek operation
// processing.
//**************************************************

public static void Main()
{
// Create an instance of MessageQueue. Set its formatter.
MessageQueue myQueue = new MessageQueue(".\\myQueue");
myQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(String)});

// Add an event handler for the PeekCompleted event.
myQueue.PeekCompleted += new
PeekCompletedEventHandler(MyPeekCompleted);

// Begin the asynchronous peek operation.
myQueue.BeginPeek();

// Do other work on the current thread.

return;
}

//**************************************************
// Provides an event handler for the PeekCompleted
// event.
//**************************************************

private static void MyPeekCompleted(Object source,
PeekCompletedEventArgs asyncResult)
{
// Connect to the queue.
MessageQueue mq = (MessageQueue)source;

// End the asynchronous peek operation.
Message m = mq.EndPeek(asyncResult.AsyncResult);

// Display message information on the screen.
Console.WriteLine("Message: " + (string)m.Body);

// Restart the asynchronous peek operation.
mq.BeginPeek();

return;
}
}
}
// </Snippet1>
// </Snippet1>
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,77 @@

namespace MyProject
{
/// <summary>
/// Provides a container class for the example.
/// </summary>
public class MyNewQueue
{
/// <summary>
/// Provides a container class for the example.
/// </summary>
public class MyNewQueue2
{
//**************************************************
// Provides an entry point into the application.
//
// This example performs asynchronous peek operation
// processing.
//**************************************************

//**************************************************
// Provides an entry point into the application.
//
// This example performs asynchronous peek operation
// processing.
//**************************************************
public static void Main()
{
// Create an instance of MessageQueue. Set its formatter.
MessageQueue myQueue = new MessageQueue(".\\myQueue");
myQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(String)});

public static void Main()
{
// Create an instance of MessageQueue. Set its formatter.
MessageQueue myQueue = new MessageQueue(".\\myQueue");
myQueue.Formatter = new XmlMessageFormatter(new Type[]
{typeof(String)});
// Add an event handler for the PeekCompleted event.
myQueue.PeekCompleted += new
PeekCompletedEventHandler(MyPeekCompleted);

// Add an event handler for the PeekCompleted event.
myQueue.PeekCompleted += new
PeekCompletedEventHandler(MyPeekCompleted);

// Begin the asynchronous peek operation with a time-out
// of one minute.
myQueue.BeginPeek(new TimeSpan(0,1,0));

// Do other work on the current thread.
// Begin the asynchronous peek operation with a time-out
// of one minute.
myQueue.BeginPeek(new TimeSpan(0, 1, 0));

return;
}
// Do other work on the current thread.

//**************************************************
// Provides an event handler for the PeekCompleted
// event.
//**************************************************

private static void MyPeekCompleted(Object source,
PeekCompletedEventArgs asyncResult)
{
try
{
// Connect to the queue.
MessageQueue mq = (MessageQueue)source;
return;
}

// End the asynchronous peek operation.
Message m = mq.EndPeek(asyncResult.AsyncResult);
//**************************************************
// Provides an event handler for the PeekCompleted
// event.
//**************************************************

// Display message information on the screen.
Console.WriteLine("Message: " + (string)m.Body);
private static void MyPeekCompleted(Object source,
PeekCompletedEventArgs asyncResult)
{
try
{
// Connect to the queue.
MessageQueue mq = (MessageQueue)source;

// Restart the asynchronous peek operation, with the
// same time-out.
mq.BeginPeek(new TimeSpan(0,1,0));
}
// End the asynchronous peek operation.
Message m = mq.EndPeek(asyncResult.AsyncResult);

catch(MessageQueueException e)
{
if (e.MessageQueueErrorCode ==
MessageQueueErrorCode.IOTimeout)
{
Console.WriteLine(e.ToString());
}
// Display message information on the screen.
Console.WriteLine("Message: " + (string)m.Body);

// Handle other sources of MessageQueueException.
}

// Handle other exceptions.

return;
}
}
// Restart the asynchronous peek operation, with the
// same time-out.
mq.BeginPeek(new TimeSpan(0, 1, 0));
}

catch (MessageQueueException e)
{
if (e.MessageQueueErrorCode ==
MessageQueueErrorCode.IOTimeout)
{
Console.WriteLine(e.ToString());
}

// Handle other sources of MessageQueueException.
}

// Handle other exceptions.

return;
}
}
}
// </Snippet1>
// </Snippet1>
Loading