|
-
Sep 14th, 2012, 09:54 AM
#1
Thread Starter
Hyperactive Member
ContextSwitch Deadlock - Timer infinite loop.
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.
VB Version: Microsoft Visual Studio 2008 Professional Edition
.NET Version: Microsoft .NET Framework Version 3.5
OS: Windows XP SP3
-
Sep 14th, 2012, 10:01 AM
#2
Re: ContextSwitch Deadlock - Timer infinite loop.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Sep 14th, 2012, 06:18 PM
#3
Thread Starter
Hyperactive Member
Re: ContextSwitch Deadlock - Timer infinite loop.
 Originally Posted by dunfiddlin
Ok. Thanks.
I got a solution from a link on that article..
http://msdn.microsoft.com/en-us/library/d21c150d.aspx
Followed these steps.
However, disabling the hosting process can affect performance. You can avoid the need to disable MDAs by preventing Visual Studio from displaying the MDA dialog box whenever an MDA notification is received. To do that, click Exceptions on the Debug menu, expand the Managed Debugging Assistants list, and then select or clear the Thrown check box for the individual MDA.
Seems to be working fine now. I also check the CPU Usage and it doesn't go beyong 10%. Hopefully that solves it.
VB Version: Microsoft Visual Studio 2008 Professional Edition
.NET Version: Microsoft .NET Framework Version 3.5
OS: Windows XP SP3
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|