Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - StateObject Class - Location

Tags:

c#

class

system

This should hopefully be a simple one.

I am trying to learn about the Socket.BeginAccept Method from http://msdn.microsoft.com/en-us/library/bysfec7w.aspx

When creating the AcceptReceiveCallback method, you need to call an instance of the StateObject class, but intellisense on Visual Studio doesn't recognise this and the code doesn't compile.

I am using the System reference as well as several others.

Thankyou

like image 362
JMK Avatar asked Mar 24 '26 10:03

JMK


1 Answers

No, you don't need to pass a StateObject. It seems, that the example on that page is icomplete, because the StateObject is not defined. You can pass any object or even null. The BeginAccept method does not care. All it does is pass the value of that parameter to EndAccept method, where you can extract it from the AsyncState property of the asyncResult you can access from the EndAccept method.

This allows you to transport any information you might need in the EndAccept method from the BeginAccept method.

like image 133
Henning Krause Avatar answered Mar 26 '26 23:03

Henning Krause



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!