I have a web application that uses threading that runs fine when compilation debug is set to true however as soon as it is set to false the page causes a spike in CPU and never loads.
I created a very simplified version of the code in order to test this issue which is below.
EDIT: Note that the aim of the Do While JobFinished < 1 Loop is to keep the page from loading until all the threads have completed so I can display the result of the calculation within the thread to the user. This doesn't seem to be a problem when compilation debug is set to true.
All help much appreciated.
Imports System.Xml
Imports System.IO
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Data
Imports System.Math
Imports System.Threading
Partial Class _Default
Inherits System.Web.UI.Page
Protected MyThread As Thread
Protected WithEvents myRequest As engineThread
Protected JobFinished As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ltMessage.Text = "<root>"
myRequest = New engineThread()
MyThread = New Thread(AddressOf myRequest.callEngine)
MyThread.Start()
Do While JobFinished < 1
Loop
ltMessage.Text &= "</root>"
End Sub
Public Sub engineHandler1() Handles myRequest.ThreadComplete
ltMessage.Text &= "It Works!"
JobFinished = JobFinished + 1
End Sub
Public Class engineThread
Public Event ThreadComplete()
Public Sub callEngine()
RaiseEvent ThreadComplete()
End Sub
End Class
End Class
My web.config is simply as follows
<configuration>
<system.web>
<compilation debug="false" strict="false" explicit="true" targetFramework="4.0" />
<httpRuntime targetFramework="4.0" executionTimeout="600" />
</system.web>
</configuration>