|
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Diagnostics;
using System.Threading;
namespace EventBasedAsync
{
class Program
{
private const string InvalidArgumentMessage = "Invalid argument. Thread pool limits were not changed.";
static void Main(string[] args)
{
Process currentProcess = Process.GetCurrentProcess();
RemotingConfiguration.Configure(currentProcess.MainModule.FileName + ".config", false);
Server server = new Server();
RemotingServices.Marshal(server, "Server.rem");
for (; ; )
{
Console.Write("> ");
string cmd = Console.ReadLine().ToLower();
string[] tokens = cmd.Split(' ');
int workerThreads, completionPortThreads, arg;
if (tokens.Length == 1 && tokens[0] == "q")
{
Console.WriteLine("Goodbye!");
Thread.Sleep(1000);
break;
}
else if (tokens.Length == 1 && tokens[0] == "g")
{
int minWorkerThreads, minCompletionPortThreads, maxWorkerThreads, maxCompletionPortThreads;
ThreadPool.GetMinThreads(out minWorkerThreads, out minCompletionPortThreads);
ThreadPool.GetMaxThreads(out maxWorkerThreads, out maxCompletionPortThreads);
Console.WriteLine("Component Min Max");
Console.WriteLine("----------------------------------");
Console.WriteLine("Worker {0,5} {1,5}", minWorkerThreads, maxWorkerThreads);
Console.WriteLine("IO Completion {0,5} {1,5}", minCompletionPortThreads, maxCompletionPortThreads);
}
else if (tokens.Length == 2 && tokens[0] == "sminw" && int.TryParse(tokens[1], out arg))
{
ThreadPool.GetMinThreads(out workerThreads, out completionPortThreads);
if (!ThreadPool.SetMinThreads(arg, completionPortThreads))
{
Console.Error.WriteLine(InvalidArgumentMessage);
}
}
else if (tokens.Length == 2 && tokens[0] == "sminc" && int.TryParse(tokens[1], out arg))
{
ThreadPool.GetMinThreads(out workerThreads, out completionPortThreads);
if (!ThreadPool.SetMinThreads(workerThreads, arg))
{
Console.Error.WriteLine(InvalidArgumentMessage);
}
}
else if (tokens.Length == 2 && tokens[0] == "smaxw" && int.TryParse(tokens[1], out arg))
{
ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads);
if (!ThreadPool.SetMaxThreads(arg, completionPortThreads))
{
Console.Error.WriteLine(InvalidArgumentMessage);
}
}
else if (tokens.Length == 2 && tokens[0] == "smaxc" && int.TryParse(tokens[1], out arg))
{
ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads);
if (!ThreadPool.SetMaxThreads(workerThreads, arg))
{
Console.Error.WriteLine(InvalidArgumentMessage);
}
}
else
{
Console.Error.WriteLine("Syntax error!\a");
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I got my B.Sc. in Mathematics and Computer Science from Tel Aviv University in 1997. Since then I have developed software in UNIX, Win32 and .NET. I currently live in Haifa.