Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > BeginReceive not ASYNC.
User Name
Password
REGISTER NOW! Mark Forums Read




Reply Bookmark and Share
1 15th April 15:37
bob
External User
 
Posts: 1
Default BeginReceive not ASYNC.



Can someone tell my why when I call Socket.BeginReceive() the callback is
called on the same thread? I thought that BeginReceive was ALWAYS an async
method. Below is the call stack. You can see its calling my callback
"Connection()" from the same thread.

My problem is that I call Accept() then BeginReceive(). If its processed on
the same thread then other connections will not be accepted. I could pass
it to another thread myself but shouldn't BeginReceive work this way?

MyApp.exe!MyApp.MStore.Connection(System.IAsyncRes ult iar =
{System.Net.Sockets.OverlappedAsyncResult}) Line 416 + 0x32 bytes C#

System.dll!System.Net.LazyAsyncResult.Complete(Sys tem.IntPtr userToken) +
0x7f bytes

System.dll!System.Net.ContextAwareResult.CaptureOr Complete(ref
System.Threading.ExecutionContext cachedContext, bool returnContext) + 0x12b
bytes

System.dll!System.Net.ContextAwareResult.FinishPos tingAsyncOp(ref
System.Net.CallbackClosure closure = null) + 0x69 bytes

System.dll!System.Net.Sockets.Socket.BeginReceive( byte[] buffer, int offset,
int size, System.Net.Sockets.SocketFlags socketFlags, out
System.Net.Sockets.SocketError errorCode, System.AsyncCallback callback,
object state) + 0x14d bytes

System.dll!System.Net.Sockets.Socket.BeginReceive( byte[] buffer, int offset,
int size, System.Net.Sockets.SocketFlags socketFlags, System.AsyncCallback
callback, object state) + 0x23 bytes

MyApp.exe!MyApp.MStore.WorkerThread() Line 625 + 0x38 bytes C#
  Reply With Quote


 


2 15th April 15:37
vadym stetsyak
External User
 
Posts: 1
Default BeginReceive not ASYNC.



The async request may complete synchronously, this comes from the internal
GetOverlappedResult function
of the kernel32.dll

if GetOverlappedResult call sets the result to WSA_IO_PENDING - then new
thread is spawned and you wait for operation completion.
if result is 0 ( no error ) operation is considered to be complete - the
same thread is used to process the callback
( you should check IAsyncResult.CompletedSynchronously to define this )
all the other results indicate that error happened.

Generally, if your callback takes much time to execute you can put the work
there on the separate thread, but this must be done only when
IAsyncResult.CompletedSynchronously is equal to true.

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com
  Reply With Quote


 


Reply


Thread Tools
Display Modes


Some other forums that might be of your interest : Development, Ada, Apple script, Assembler, Awk, Beos, Basic, C, C++, C#, C# .net, .net, .net frameworks, Asp .net, Clarion, Clipper, Clos, Clu, Cobol, Coldfusion, Delphi, Dylan, Eiffel, Forth, Fortran, Haskell, Hermes, Icon, Idl, Java, Java script, Jscript .net, Jcl, Linoleum, Lisp, Lotus, Limbo, Logo, Ml, Mumps, Oberon, Postscript, Pop, Pl1, Prolog, Python, Ruby, Pascal, Perl, Php, Rebol, Rexx, Sed, Sather, Scheme, Smalltalk, Tcl, Vhdl, Vrml, Visual basic, Visual basic .net, Yorick, Mysql, Omnis, Postgresql, Xbase, Access, Oracle, Adabas, Berkeley, Btrieve, Filemaker, Gupta, Db2, Informix, Ingres, Mssql server, Object, Olap, Paradox, Rdb, Revelation, Sybase, Theory, Dbase, Html, Java script, Css, Flash, Photoshop, Corel script, Xml, Tech, Beos, Gem, Hp48, Hpux, Linux, Mac, Ms-dos, Os2, Palm, Solaris, Ti99, Windows, Xenix, Aos, Chorus, Geos, Inferno, Lantastic, Lynx, Mach, Minix, Netware, Os9, Parix, Plan9, Psos, Qnx, Xinu, Sco, Unix, Aix, Aux, 386bsd, Bsdi, Freebsd, Netbsd, Openbsd, Ultrix, Amd, Intel, Aptiva, Buz, Deals, Homebuilt, Overclocking, Programming, Extra forums


Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666