Skip to content

Commit 1e6666e

Browse files
authored
add project files and fix warnings (dotnet#9677)
1 parent e7a3457 commit 1e6666e

File tree

46 files changed

+1030
-1016
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1030
-1016
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net481</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="6.0.0" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<Reference Include="System.Messaging" />
14+
</ItemGroup>
15+
16+
</Project>

snippets/csharp/System.Messaging/MessageQueue/.ctor/class1.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,18 @@ public class QueueExample
77
{
88
public static void Main()
99
{
10-
// Create a new instance of the class.
11-
QueueExample example = new QueueExample();
12-
1310
// Create a nontransactional queue on the local computer.
1411
CreateQueue(".\\exampleQueue", false);
1512

16-
example.UseQueue();
13+
UseQueue();
1714

1815
return;
1916
}
2017

2118
// Create a new queue.
2219
public static void CreateQueue(string queuePath, bool transactional)
2320
{
24-
if(!MessageQueue.Exists(queuePath))
21+
if (!MessageQueue.Exists(queuePath))
2522
{
2623
MessageQueue.Create(queuePath, transactional);
2724
}
@@ -31,7 +28,7 @@ public static void CreateQueue(string queuePath, bool transactional)
3128
}
3229
}
3330

34-
public void UseQueue()
31+
public static void UseQueue()
3532
{
3633
// <snippet1>
3734
// Connect to a queue on the local computer. You must set the queue's

snippets/csharp/System.Messaging/MessageQueue/.ctor/class11.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,22 @@
33
using System;
44
using System.Messaging;
55

6-
public class QueueExample
6+
public class QueueExample2
77
{
88
public static void Main()
99
{
10-
// Create a new instance of the class.
11-
QueueExample example = new QueueExample();
12-
1310
// Create a nontransactional queue on the local computer.
1411
CreateQueue(".\\exampleQueue", false);
1512

16-
example.UseQueue();
13+
UseQueue();
1714

1815
return;
1916
}
2017

2118
// Create a new queue.
2219
public static void CreateQueue(string queuePath, bool transactional)
2320
{
24-
if(!MessageQueue.Exists(queuePath))
21+
if (!MessageQueue.Exists(queuePath))
2522
{
2623
MessageQueue.Create(queuePath, transactional);
2724
}
@@ -31,7 +28,7 @@ public static void CreateQueue(string queuePath, bool transactional)
3128
}
3229
}
3330

34-
public void UseQueue()
31+
public static void UseQueue()
3532
{
3633
// <snippet1>
3734
// Connect to a queue on the local computer, grant exclusive read

snippets/csharp/System.Messaging/MessageQueue/.ctor/mqctor_denysharedreceive.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ namespace MyProject
99
/// </summary>
1010
public class MyNewQueue
1111
{
12-
1312
//**************************************************
1413
// Provides an entry point into the application.
1514
//
@@ -22,8 +21,8 @@ public static void Main()
2221
// Create a new instance of the class.
2322
MyNewQueue myNewQueue = new MyNewQueue();
2423

25-
// Output the count of Lowest priority messages.
26-
myNewQueue.GetExclusiveAccess();
24+
// Output the count of Lowest priority messages.
25+
GetExclusiveAccess();
2726

2827
return;
2928
}
@@ -34,7 +33,7 @@ public static void Main()
3433
// queue.
3534
//**************************************************
3635

37-
public void GetExclusiveAccess()
36+
public static void GetExclusiveAccess()
3837
{
3938
try
4039
{
@@ -65,4 +64,4 @@ public void GetExclusiveAccess()
6564
}
6665
}
6766
}
68-
// </Snippet1>
67+
// </Snippet1>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net481</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="6.0.0" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<Reference Include="System.Messaging" />
14+
</ItemGroup>
15+
16+
</Project>

snippets/csharp/System.Messaging/MessageQueue/BeginPeek/mqbeginpeek_noparms.cs

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,59 @@
44

55
namespace MyProject
66
{
7-
/// <summary>
8-
/// Provides a container class for the example.
9-
/// </summary>
10-
public class MyNewQueue
11-
{
12-
13-
//**************************************************
14-
// Provides an entry point into the application.
15-
//
16-
// This example performs asynchronous peek operation
17-
// processing.
18-
//**************************************************
19-
20-
public static void Main()
21-
{
22-
// Create an instance of MessageQueue. Set its formatter.
23-
MessageQueue myQueue = new MessageQueue(".\\myQueue");
24-
myQueue.Formatter = new XmlMessageFormatter(new Type[]
25-
{typeof(String)});
26-
27-
// Add an event handler for the PeekCompleted event.
28-
myQueue.PeekCompleted += new
29-
PeekCompletedEventHandler(MyPeekCompleted);
30-
31-
// Begin the asynchronous peek operation.
32-
myQueue.BeginPeek();
33-
34-
// Do other work on the current thread.
35-
36-
return;
37-
}
38-
39-
//**************************************************
40-
// Provides an event handler for the PeekCompleted
41-
// event.
42-
//**************************************************
43-
44-
private static void MyPeekCompleted(Object source,
45-
PeekCompletedEventArgs asyncResult)
46-
{
47-
// Connect to the queue.
48-
MessageQueue mq = (MessageQueue)source;
49-
50-
// End the asynchronous peek operation.
51-
Message m = mq.EndPeek(asyncResult.AsyncResult);
52-
53-
// Display message information on the screen.
54-
Console.WriteLine("Message: " + (string)m.Body);
55-
56-
// Restart the asynchronous peek operation.
57-
mq.BeginPeek();
58-
59-
return;
60-
}
61-
}
7+
/// <summary>
8+
/// Provides a container class for the example.
9+
/// </summary>
10+
public class MyNewQueue
11+
{
12+
//**************************************************
13+
// Provides an entry point into the application.
14+
//
15+
// This example performs asynchronous peek operation
16+
// processing.
17+
//**************************************************
18+
19+
public static void Main()
20+
{
21+
// Create an instance of MessageQueue. Set its formatter.
22+
MessageQueue myQueue = new MessageQueue(".\\myQueue");
23+
myQueue.Formatter = new XmlMessageFormatter(new Type[]
24+
{typeof(String)});
25+
26+
// Add an event handler for the PeekCompleted event.
27+
myQueue.PeekCompleted += new
28+
PeekCompletedEventHandler(MyPeekCompleted);
29+
30+
// Begin the asynchronous peek operation.
31+
myQueue.BeginPeek();
32+
33+
// Do other work on the current thread.
34+
35+
return;
36+
}
37+
38+
//**************************************************
39+
// Provides an event handler for the PeekCompleted
40+
// event.
41+
//**************************************************
42+
43+
private static void MyPeekCompleted(Object source,
44+
PeekCompletedEventArgs asyncResult)
45+
{
46+
// Connect to the queue.
47+
MessageQueue mq = (MessageQueue)source;
48+
49+
// End the asynchronous peek operation.
50+
Message m = mq.EndPeek(asyncResult.AsyncResult);
51+
52+
// Display message information on the screen.
53+
Console.WriteLine("Message: " + (string)m.Body);
54+
55+
// Restart the asynchronous peek operation.
56+
mq.BeginPeek();
57+
58+
return;
59+
}
60+
}
6261
}
63-
// </Snippet1>
62+
// </Snippet1>

snippets/csharp/System.Messaging/MessageQueue/BeginPeek/mqbeginpeek_timeout.cs

Lines changed: 63 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,78 +4,77 @@
44

55
namespace MyProject
66
{
7-
/// <summary>
8-
/// Provides a container class for the example.
9-
/// </summary>
10-
public class MyNewQueue
11-
{
7+
/// <summary>
8+
/// Provides a container class for the example.
9+
/// </summary>
10+
public class MyNewQueue2
11+
{
12+
//**************************************************
13+
// Provides an entry point into the application.
14+
//
15+
// This example performs asynchronous peek operation
16+
// processing.
17+
//**************************************************
1218

13-
//**************************************************
14-
// Provides an entry point into the application.
15-
//
16-
// This example performs asynchronous peek operation
17-
// processing.
18-
//**************************************************
19+
public static void Main()
20+
{
21+
// Create an instance of MessageQueue. Set its formatter.
22+
MessageQueue myQueue = new MessageQueue(".\\myQueue");
23+
myQueue.Formatter = new XmlMessageFormatter(new Type[]
24+
{typeof(String)});
1925

20-
public static void Main()
21-
{
22-
// Create an instance of MessageQueue. Set its formatter.
23-
MessageQueue myQueue = new MessageQueue(".\\myQueue");
24-
myQueue.Formatter = new XmlMessageFormatter(new Type[]
25-
{typeof(String)});
26+
// Add an event handler for the PeekCompleted event.
27+
myQueue.PeekCompleted += new
28+
PeekCompletedEventHandler(MyPeekCompleted);
2629

27-
// Add an event handler for the PeekCompleted event.
28-
myQueue.PeekCompleted += new
29-
PeekCompletedEventHandler(MyPeekCompleted);
30-
31-
// Begin the asynchronous peek operation with a time-out
32-
// of one minute.
33-
myQueue.BeginPeek(new TimeSpan(0,1,0));
34-
35-
// Do other work on the current thread.
30+
// Begin the asynchronous peek operation with a time-out
31+
// of one minute.
32+
myQueue.BeginPeek(new TimeSpan(0, 1, 0));
3633

37-
return;
38-
}
34+
// Do other work on the current thread.
3935

40-
//**************************************************
41-
// Provides an event handler for the PeekCompleted
42-
// event.
43-
//**************************************************
44-
45-
private static void MyPeekCompleted(Object source,
46-
PeekCompletedEventArgs asyncResult)
47-
{
48-
try
49-
{
50-
// Connect to the queue.
51-
MessageQueue mq = (MessageQueue)source;
36+
return;
37+
}
5238

53-
// End the asynchronous peek operation.
54-
Message m = mq.EndPeek(asyncResult.AsyncResult);
39+
//**************************************************
40+
// Provides an event handler for the PeekCompleted
41+
// event.
42+
//**************************************************
5543

56-
// Display message information on the screen.
57-
Console.WriteLine("Message: " + (string)m.Body);
44+
private static void MyPeekCompleted(Object source,
45+
PeekCompletedEventArgs asyncResult)
46+
{
47+
try
48+
{
49+
// Connect to the queue.
50+
MessageQueue mq = (MessageQueue)source;
5851

59-
// Restart the asynchronous peek operation, with the
60-
// same time-out.
61-
mq.BeginPeek(new TimeSpan(0,1,0));
62-
}
52+
// End the asynchronous peek operation.
53+
Message m = mq.EndPeek(asyncResult.AsyncResult);
6354

64-
catch(MessageQueueException e)
65-
{
66-
if (e.MessageQueueErrorCode ==
67-
MessageQueueErrorCode.IOTimeout)
68-
{
69-
Console.WriteLine(e.ToString());
70-
}
55+
// Display message information on the screen.
56+
Console.WriteLine("Message: " + (string)m.Body);
7157

72-
// Handle other sources of MessageQueueException.
73-
}
74-
75-
// Handle other exceptions.
76-
77-
return;
78-
}
79-
}
58+
// Restart the asynchronous peek operation, with the
59+
// same time-out.
60+
mq.BeginPeek(new TimeSpan(0, 1, 0));
61+
}
62+
63+
catch (MessageQueueException e)
64+
{
65+
if (e.MessageQueueErrorCode ==
66+
MessageQueueErrorCode.IOTimeout)
67+
{
68+
Console.WriteLine(e.ToString());
69+
}
70+
71+
// Handle other sources of MessageQueueException.
72+
}
73+
74+
// Handle other exceptions.
75+
76+
return;
77+
}
78+
}
8079
}
81-
// </Snippet1>
80+
// </Snippet1>

0 commit comments

Comments
 (0)