unhandled ObjectDisposedException though exception handler provided

Last post 11-18-2008 4:17 PM by davidebb. 2 replies.

Sort Posts:

  • unhandled ObjectDisposedException though exception handler provided

    11-17-2008, 6:23 AM
    • Member
      point Member
    • SheetalP
    • Member since 11-13-2008, 4:15 AM
    • Posts 3

    Hi,

    I am writing a serial port communication application using Iron Python. Following is my code:

     class serial:
          
        def sendMessage( self, entity, command, endstring ):

            try:
                BaudRate = 9600
                DataBits = 8           
                comPort = "COM1"

              
    #create a serial port instance for the desired port as specified
                serialPort = System.IO.Ports.SerialPort( comPort )
              
                serialPort.BaudRate = BaudRate 

                serialPort.DataBits = DataBits

    #open the port
                serialPort.Close()
                serialPort.Open()

                serialPort.ReadTimeout = 30000

                serialPort.Write( command )

                returnValue = serialPort.ReadTo( endstring )
            except:
                print "error"
                returnValue = ""

            serialPort.Close()
            serialPort.Dispose()

            return returnValue

       
    com1 = serial()
    a = com1.sendMessage( "ABC", "2", "B" )

     

    Here if i abort my application using Cntrl + C then i get ObjectDisposedException unhandled though i have provided an exception handler.

    Can you please help me with the same.................

     

  • Re: unhandled ObjectDisposedException though exception handler provided

    11-17-2008, 11:34 PM
    • Member
      point Member
    • SheetalP
    • Member since 11-13-2008, 4:15 AM
    • Posts 3

    Following is the stack trace which i got: 

    at Microsoft.Win32.Win32Native.SetEvent(SafeWaitHandle handle) at System.Threading.EventWaitHandle.Set() at System.IO.Ports.SerialStream.AsyncFSCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOverlapped) at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

    Also i tried to abort the application using Ctrl + C while it was waiting for some data to be read and timeout had not occured.

    The application exits and I get the exception after it exits.

     Please let me know if its possible to catch this exception in the current scenario.

  • Re: unhandled ObjectDisposedException though exception handler provided

    11-18-2008, 4:17 PM
    Answer
    • Contributor
      5,815 point Contributor
    • davidebb
    • Member since 06-11-2002, 8:31 AM
    • Redmond, WA
    • Posts 1,162
    • AspNetTeam

    Note that this forum is specifically for discussing issues relating to the use of IronPython in an ASP.NET app.  For general IronPython issue, please check out the Codeplex site, which explains how to join the discussion list.

    thanks,
    David

Page 1 of 1 (3 items)