New async socket behavior?

D

Darren

Hi all,

My company has recently migrated an application from .Net 1.1 to .Net
2.0. It uses the Socket class to perform some network
communications. When Calling the BeginConnect() method, I have
noticed that sometimes the specified AsyncCallback method will
actually get called from the same thread as the BeginConnect() call
was made from, prior to the the BeginConnect() call returning (i.e.
same thread, same call stack).

In .Net 1.1, the callback was always performed on a separate thread.
I've even gone back and run some tests to verify this. I guess I
would just like some confirmation. Did this behavior change between
version 1.1 and 2.0? Is this a bug in .Net 2.0? The documentation
for BeginConnect() explicitly states "the system will use a separate
thread to execute the specified callback method."

This caused an issue in our application that we were able to easily
correct, but I wanted to throw this out there in case anyone else is
experiencing a similar problem.

Thanks!
--Darren
 
C

Chris Mullins [MVP - C#]

I've noticed similar behavior in the Async ASP.Net infrastructure, but not
in Sockets.

I know that in some of our custom implemented IAsyncResult classes, we hit
some strane errors around this - but again, they were all in ASP.Net.

Personally, if the runtime is able to eliminate the context switch, I think
it's a good thing. I can see where it would be a bit frustrating though to
have it happen in an unexpected chunk of code....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top