Click here to Skip to main content
15,915,740 members
Home / Discussions / C#
   

C#

 
AnswerRe: Very Simple HTML Parser C# Pin
PIEBALDconsult21-Jul-10 14:23
mvePIEBALDconsult21-Jul-10 14:23 
GeneralRe: Very Simple HTML Parser C# Pin
justme8921-Jul-10 14:27
justme8921-Jul-10 14:27 
GeneralRe: Very Simple HTML Parser C# Pin
Ravi Bhavnani21-Jul-10 18:34
professionalRavi Bhavnani21-Jul-10 18:34 
GeneralRe: Very Simple HTML Parser C# Pin
jschell22-Jul-10 8:27
jschell22-Jul-10 8:27 
AnswerRe: Very Simple HTML Parser C# Pin
V.21-Jul-10 20:59
professionalV.21-Jul-10 20:59 
GeneralRe: Very Simple HTML Parser C# Pin
Luc Pattyn21-Jul-10 21:05
sitebuilderLuc Pattyn21-Jul-10 21:05 
GeneralRe: Very Simple HTML Parser C# Pin
V.21-Jul-10 22:53
professionalV.21-Jul-10 22:53 
QuestionSeriously silly sockets - please assist Pin
GrenMeera21-Jul-10 9:56
GrenMeera21-Jul-10 9:56 
I have been having some difficulty in a C# application that uses a UDP socket connection. Everything works all sorts of fancy and fun until the closing of my Form application, and then I can't seem to stop receiving messages.

I always get some form of exception inside of the receive callback stating that the socket is disposed. This is, of course, true. The problem is, why am I getting a message after I have closed down and shutdown the sockets? I'm not too familiar with every in and out of C# (don't think I'll ever get used to managed code. Can I have C back?) Included, I have the receive callback, which parses a message and continues to listen. I also included the CloseConnections method, which is called within the Form Closing event.

Does Shutdown and Close not stop the messages from being received? If so, how can I so that the GC may dispose of my sockets without receiving a message afterwards?

"An unhandled exception of type 'System.ObjectDisposedException' occurred in system.dll
Additional information: Cannot access a disposed object named "System.Net.Sockets.Socket"."

private static void ReceiveCallback(IAsyncResult ar)
{
	// End Receive
	StateObject stateObject = (StateObject)ar.AsyncState;

	if(stateObject != null && stateObject.Socket != null && stateObject.DataBuffer != null && stateObject.EventMap != null)
	{
		int bytesReceived = stateObject.Socket.EndReceive(ar);

		if(bytesReceived > 0)
		{
			// Parse Data
			SocketConnection.ParseReceiveBuffer(stateObject);
		}
	}
	if(stateObject != null && stateObject.Socket != null && stateObject.DataBuffer != null && stateObject.EventMap != null)
	{
		// Begin Receive
		stateObject.Socket.BeginReceive(stateObject.DataBuffer, 0, stateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), stateObject);
	}
}


public void CloseConnections()
{
	// Receive
	if(_recvSocket != null)
	{
		_recvSocket.Shutdown(SocketShutdown.Both);
		_recvSocket.Close();
		_recvSocket = null;
		_recvState.Socket = null;
		_recvState = null;
	}

	// Send
	if(_sendSocket != null)
	{
		_sendSocket.Shutdown(SocketShutdown.Both);
		_sendSocket.Close();
		_sendSocket = null;
		_sendState.Socket = null;
		_sendState = null;
	}
}

AnswerRe: Seriously silly sockets - please assist Pin
Jimmanuel21-Jul-10 10:34
Jimmanuel21-Jul-10 10:34 
GeneralRe: Seriously silly sockets - please assist Pin
GrenMeera22-Jul-10 5:11
GrenMeera22-Jul-10 5:11 
GeneralRe: Seriously silly sockets - please assist Pin
Jimmanuel22-Jul-10 7:26
Jimmanuel22-Jul-10 7:26 
AnswerRe: Seriously silly sockets - please assist Pin
LimitedAtonement21-Jul-10 10:42
LimitedAtonement21-Jul-10 10:42 
GeneralRe: Seriously silly sockets - please assist Pin
GrenMeera22-Jul-10 5:18
GrenMeera22-Jul-10 5:18 
GeneralRe: Seriously silly sockets - please assist Pin
jschell22-Jul-10 8:38
jschell22-Jul-10 8:38 
QuestionRe: Seriously silly sockets - please assist Pin
Jimmanuel22-Jul-10 9:20
Jimmanuel22-Jul-10 9:20 
QuestionOnly in Release config, SetWindowsHookEx throws error 80004005 Pin
LimitedAtonement21-Jul-10 9:36
LimitedAtonement21-Jul-10 9:36 
AnswerRe: Only in Release config, SetWindowsHookEx throws error 80004005 Pin
Dave Kreskowiak21-Jul-10 10:22
mveDave Kreskowiak21-Jul-10 10:22 
Question? : Operator Pin
I Believe In GOD21-Jul-10 7:00
I Believe In GOD21-Jul-10 7:00 
AnswerRe: ? : Operator PinPopular
harold aptroot21-Jul-10 7:02
harold aptroot21-Jul-10 7:02 
GeneralRe: ? : Operator Pin
I Believe In GOD21-Jul-10 7:06
I Believe In GOD21-Jul-10 7:06 
GeneralRe: ? : Operator Pin
harold aptroot21-Jul-10 7:13
harold aptroot21-Jul-10 7:13 
GeneralRe: ? : Operator Pin
I Believe In GOD21-Jul-10 7:12
I Believe In GOD21-Jul-10 7:12 
AnswerRe: ? : Operator Pin
Luc Pattyn21-Jul-10 7:02
sitebuilderLuc Pattyn21-Jul-10 7:02 
GeneralRe: ? : Operator Pin
I Believe In GOD21-Jul-10 7:10
I Believe In GOD21-Jul-10 7:10 
GeneralRe: ? : Operator Pin
Roger Wright21-Jul-10 7:54
professionalRoger Wright21-Jul-10 7:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.