Hi,

I need to create an application that will check certain records from the database and then do some processing on these records. These needs to be done every few seconds. I have now a console application that does this and used Timer class for the loop. Problem I'm getting is that I get the ContextSwitch Deadlock error.

Code:
Imports System.Data.OracleClient

Module Standard

    Private ORACLEXE_OracleConnection As New OracleConnection
    Private ORACLEXE_OracleConnectionStringBuilder As New OracleConnectionStringBuilder
    Private APPCONCURRENTREQUEST_DataTable As New DataTable
    Private APPCONCURRENTREQUEST_DataAdapter As New OracleDataAdapter
    Private APPCONCURRENTREQUEST_SelectCommand As New OracleCommand
    Private APPCONCURRENTREQUEST_UpdateCommand As New OracleCommand

    Private Function ExecutableFile(ByVal intProgramId As Integer) As String
        Dim strExecutableFile As String = String.Empty
        Dim drExecutableFile As OracleDataReader
        Dim selExecutableFile As New OracleCommand

        With selExecutableFile
            .CommandType = CommandType.Text
            .CommandText = "select ad.directory_path || '\' || se.executable_file_name " _
                         & "  from fnd_concurrent_programs scp" _
                         & "     , fnd_executables se" _
                         & "     , fnd_executable_types st" _
                         & "     , fnd_applications sa" _
                         & "     , all_directories ad" _
                         & " where scp.executable_id = se.executable_id" _
                         & "   and se.executable_type_code = st.executable_type_code" _
                         & "   and se.application_id = sa.application_id" _
                         & "   and ad.directory_name = sa.application_base || st.executable_base" _
                         & "   and scp.concurrent_program_id = :concurrent_program_id"
            .Parameters.AddWithValue("concurrent_program_id", intProgramId)
            .Connection = ORACLEXE_OracleConnection
        End With

        drExecutableFile = selExecutableFile.ExecuteReader

        Do While drExecutableFile.Read
            strExecutableFile = drExecutableFile.GetString(0)
        Loop

        Return strExecutableFile
    End Function

    Private Sub Check()
        ' For each row, print the values of each column. 
        Dim row As DataRow

        For Each row In APPCONCURRENTREQUEST_DataTable.Rows
            Console.WriteLine(ExecutableFile(row("CONCURRENT_PROGRAM_ID")))
        Next row
    End Sub


    Sub Main()
        Try
            With ORACLEXE_OracleConnectionStringBuilder
                .DataSource = "XE"
                .UserID = "USER"
                .Password = "pass"
            End With

            With ORACLEXE_OracleConnection
                .ConnectionString = ORACLEXE_OracleConnectionStringBuilder.ConnectionString
                .Open()
            End With

            With APPCONCURRENTREQUEST_SelectCommand
                .CommandType = CommandType.Text
                .CommandText = "select * from fnd_concurrent_requests where phase_code = 'P' order by requested_start_date"
                .Connection = ORACLEXE_OracleConnection
            End With

            With APPCONCURRENTREQUEST_UpdateCommand
                .CommandType = CommandType.Text
                .CommandText = "update fnd_concurrent_requests set phase_code = 'R' and pid = :pid where request_id = :request_id"
                .Connection = ORACLEXE_OracleConnection
            End With

            With APPCONCURRENTREQUEST_DataAdapter
                .SelectCommand = APPCONCURRENTREQUEST_SelectCommand
                .UpdateCommand = APPCONCURRENTREQUEST_UpdateCommand
                .Fill(APPCONCURRENTREQUEST_DataTable)
            End With

            Dim timerStandard As New Timers.Timer
            With timerStandard
                '.AutoReset = True
                .Interval = 10000
                AddHandler timerStandard.Elapsed, AddressOf timerStandard_Tick
                .Start()
                Console.ReadKey()
            End With

        Catch ex As Exception
            ORACLEXE_OracleConnection.Close()
            ORACLEXE_OracleConnection.Dispose()

        Finally
            ORACLEXE_OracleConnection.Close()
            ORACLEXE_OracleConnection.Dispose()

        End Try

    End Sub

    Private Sub timerStandard_Tick(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
        Console.WriteLine("Tick")
        Check()
    End Sub

End Module
How do I fix this error? It doesn't occur until for about a minute or so.

Thanks.