|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WCFClient
{
class Program
{
public static int Threads;
public static int DoneThreads;
public static int ErrorThreads;
static void Main(string[] args)
{
Threads = 20;
DoneThreads = 0;
SpawnThreads(Threads);
Console.ReadLine();
}
public delegate bool ThreadDelegate();
public static void SpawnThreads(int threads)
{
for (int i = 0; i < threads; i++)
{
ThreadDelegate del = new ThreadDelegate(CallProxy);
IAsyncResult result = del.BeginInvoke(delegate(IAsyncResult r) { EndCall(del.EndInvoke(r)); }, null);
}
}
public static bool CallProxy()
{
try
{
Console.WriteLine( new Proxy("ThrottleTCP").Ping());
return true;
}
catch (Exception exc)
{
Console.WriteLine(-1);
//Console.WriteLine(exc.Message);//If you want some debugging
return false;
}
}
public static void EndCall(bool result)
{
if (!result)
{
ErrorThreads++;
}
DoneThreads++;
if (DoneThreads == Threads)
{
Console.WriteLine(string.Format("The {0} threads completed of which {1} failed.", DoneThreads, ErrorThreads));
}
}
}
}
|
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.
Chris is a full time software developer in London, UK.
He has a BSc in computer science and is busy taking courses in the MCTS stream.