A
Alexander Malapheev
Hello,
I'm writing an application which use APM.
For example:
class Program
{
static Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
static void Main(string[] args)
{
IAsyncResult res = socket.BeginConnect("microsoft.com", 80,
null, null);
socket.EndConnect(res);
Console.ReadLine();
}
}
In this example calling of socket.BeginConnect creates 3 additional (6 at
all) threads (as we can see in the task manager). As I understand this
method should use asynchronous call through a driver. Any way it shouldn't
use 3 additional thread - it should use only 1!
There are similar results with others BeginXXX methods, for example
FileStream.BeginRead use 2 additional threads.
It's looks like a seriouse bug in realisation of APM in .NET, or I'm wrong?
Thus it's more efficient to use something like this:
class Program
{
delegate void TestDelegate();
static Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
static void test()
{
socket.Connect("microsoft.com", 80);
}
static void Main(string[] args)
{
TestDelegate t = new TestDelegate(test);
IAsyncResult r = t.BeginInvoke(null, null);
t.EndInvoke(r);
Console.ReadLine();
}
}
In this example we have only 1 additional thread.
I'm writing an application which use APM.
For example:
class Program
{
static Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
static void Main(string[] args)
{
IAsyncResult res = socket.BeginConnect("microsoft.com", 80,
null, null);
socket.EndConnect(res);
Console.ReadLine();
}
}
In this example calling of socket.BeginConnect creates 3 additional (6 at
all) threads (as we can see in the task manager). As I understand this
method should use asynchronous call through a driver. Any way it shouldn't
use 3 additional thread - it should use only 1!
There are similar results with others BeginXXX methods, for example
FileStream.BeginRead use 2 additional threads.
It's looks like a seriouse bug in realisation of APM in .NET, or I'm wrong?
Thus it's more efficient to use something like this:
class Program
{
delegate void TestDelegate();
static Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
static void test()
{
socket.Connect("microsoft.com", 80);
}
static void Main(string[] args)
{
TestDelegate t = new TestDelegate(test);
IAsyncResult r = t.BeginInvoke(null, null);
t.EndInvoke(r);
Console.ReadLine();
}
}
In this example we have only 1 additional thread.