Results 1 to 7 of 7

Thread: SOCKET ERROR : Cannot access a disposed object

  1. #1

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    SOCKET ERROR : Cannot access a disposed object

    im kinda using ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconnon-blockingserversocketexample.htm

    as my example to socket programming

    for u that dont have msdn = http://msdn.microsoft.com/library/de...ketexample.asp


    I am getting an error of

    System.ObjectDisposedException: Cannot access a disposed object named "System.Net.Sockets.Socket".
    Object name: "System.Net.Sockets.Socket".
    at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
    at SpiderCheck.Class1.ReceiveCallback(IAsyncResult ar) in C:\Development\SpiderManager\SpiderCheck\Class1.vb:line 165

    I know what the problem is however im not sure on how to resolve it
    The problem is that the socket is getting dropped when the thread is terminated and that the BeginReceive method still has information coming in.

    This works ok when its a single call to the server but i need to run my methods within a loop, this is where the problem is caused.

    Could anyone advise on how to resolve this issue. ask if you wish to see the code snippets


    Thanks in advance

    Carl
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  2. #2

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    Re: SOCKET ERROR : Cannot access a disposed object

    bump please help
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  3. #3
    Addicted Member Latin4567's Avatar
    Join Date
    Jan 2005
    Posts
    202

    Re: SOCKET ERROR : Cannot access a disposed object

    use timers.... they are much more performance-friendly then using a loop

    sockets.... havent worked much with these. Sorry I cant be of more help

  4. #4

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    Re: SOCKET ERROR : Cannot access a disposed object

    ive managed to fix it strange thing is i was doing a call to my socket dll and updating a list box within a loop i seperated the call to my dll in to a function and now it works like a dream

    but i dont understand why ?
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  5. #5
    Member
    Join Date
    Jan 2005
    Location
    in the nederlands
    Posts
    37

    Re: SOCKET ERROR : Cannot access a disposed object

    what do you make somthing on internet, winsock is a good a very good
    script for internet but microsoft change it in a script a dam script maybe can you find somthing beters on this site

    www.planetsourcecode.com
    what is xml ???

    help my please on this link for xml
    http://www.vbforums.com/showthread.php?t=322815



  6. #6
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: SOCKET ERROR : Cannot access a disposed object

    Hi
    I had a similar problem i have a form with a crystalreportviewer and once i closed the form while the report was still pulling data and i receive a similar error.

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  7. #7
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: SOCKET ERROR : Cannot access a disposed object

    carlblanchard, are you trying to use a socket again after it's already been closed? If so, you can't do that, as the .Close() method calls dispose, and you get that error.

    The workaround is to just create a new socket rather than trying to open one that has been closed/disposed.

    HTH,
    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width