A
Alessandro De Simone
Hello,
I have to exchange data on a socket within a unique thread in dotnet.
My idea is to use a queue for writing requests and a ManualResetEvent to
detect in the socket thread when one (or more) elements are added (from
the main thread) to the queue (look at my pseudo code bellow).
But is it possible to obtain a WaitHandle to detect when there is data
available for reading in the socket ? I know I can use the
"System.IAsyncResult.AsyncWaitHandle" from a "BeginRead", but this
method use an another thread.
In Win32, you could use "WSACreateEvent" and "WSAEventSelect" to get a
HANDLE used in "WaitForMultipleObjects".
Am I missing something ? Thanks
Alessandro
---
WaitHandle[] ReadWrite = new WaitHandle[]{SocketReadEvent, QueueEvent};
while( 1 )
{
int index = WaitHandle.WaitAny(ReadWrite);
if( index == 0 )
{
// read an information (size is known) from the socket
}
else
{
// write the queue content on the socket
}
}
I have to exchange data on a socket within a unique thread in dotnet.
My idea is to use a queue for writing requests and a ManualResetEvent to
detect in the socket thread when one (or more) elements are added (from
the main thread) to the queue (look at my pseudo code bellow).
But is it possible to obtain a WaitHandle to detect when there is data
available for reading in the socket ? I know I can use the
"System.IAsyncResult.AsyncWaitHandle" from a "BeginRead", but this
method use an another thread.
In Win32, you could use "WSACreateEvent" and "WSAEventSelect" to get a
HANDLE used in "WaitForMultipleObjects".
Am I missing something ? Thanks
Alessandro
---
WaitHandle[] ReadWrite = new WaitHandle[]{SocketReadEvent, QueueEvent};
while( 1 )
{
int index = WaitHandle.WaitAny(ReadWrite);
if( index == 0 )
{
// read an information (size is known) from the socket
}
else
{
// write the queue content on the socket
}
}