unhandled ObjectDisposedException though exception handler provided

Nov 19, 2008 at 3:11 AM

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.

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.


Nov 19, 2008 at 4:16 AM
Hi SheetaIP,

This is the discussion list for the CodePlex site itself. I would recommend posting this on the Iron Python discussion list to obtain help.

Thanks,
Matt