Any general rules/practices to avoid "ObjectDisposedException"-- System.ObjectDisposedException: Cannot access a disposed object?
thanks in advance,
Simple. Never ever try to call a method of a disposed object
(or, if it's a control, check with the IsDisposed property)
Last edited by Magos; 05-12-2008 at 07:11 AM.
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Your reply is great! Let me descirbe more details here. I am writing a simple Http Server using HttpListener class in C#.
1. The exception from server side, when I call EndGetContext, not from client side;
2. On the server side, I create an HttpListener object, and waiting for incoming client request;
3. When I received a request, I will process the request asynchronously by using BeginGetContext, and in this way HttpListener object instance can still listen for incoming calls, while processing backend at the same time;
4. When sending the request to server from client, the client will close the connection immediately -- during the asynchronous processing period;
5. The server will throw exception when I call EndGetContext. At the same time, ObjectDisposedException will happen.
Any ideas why the exception will happen? I am also interested in whose Disposed method is called, any ways to detect?
Originally Posted by Magos