views:

268

answers:

1

Hello,

I'm tired of the .NET BeginRead,EndRead stuff.I'd love to use WSAAsyncSelect the way I used to in Delphi/C++

//Async CallBack handler Declaration
procedure MessageHandler(var Msg:Tmessage);Message WM_WINSOCK_ASYNC_MSG;

//Where i setup the Async
dwError := WSAAsyncSelect(Sock, form1.handle, WM_WINSOCK_ASYNC_MSG, FD_CLOSE or FD_READ);

//Async Callback Handler
procedure Tform1.MessageHandler(var Msg:Tmessage);
begin
  case WSAGetSelectEvent(MSG.LParam) of //LParam is FD_READ/FR_CLOSE/FD_WRITE
    FD_READ: OnSocketRead(MSG.WParam); //WPARAM is the Socket itself.
    FD_CLOSE: OnSocketClose(MSG.WParam);
  end;
end;

Is it possible to set that event in C#?

+1  A: 

If I understand correctly, you could use SocketAsyncEventArgs in the same pattern.

macbirdie