Reputation: 21
I am completely new in Delegate and BeginInvoke . I have a project which is written as Win form app (Vb) and now I have to change it in Web asp.net and I really dont know how I can do that: More about my project:
when I click on run button, my project runs and it caculates some data and it shows results in some textboxes till it finished . At the End the button save data enabled in order to save Results:
See it in action:
How the Project work
Run Button Function :
e.Run.Enabled = False
Me.Run.Text = "Please wait ..."
Me.simphony.Enabled = False
Me.access.Enabled = False
Me.optimizationEngineField = New OptimizationEngine(economyImportance:=0.5,
simphonyAnalysisModel:=Me.simphonyAnalysisEngine)
Dim tempThread As New Threading.Thread(Sub()
Me.bestSolutionField = Me.optimizationEngineField.StartOptimization(percentErrorTermination:=True,
maxIteration:=CInt(Me.TextBoxMaxIteration.Text),
percentError:=CDbl(Me.TextBoxAccuracy.Text))
End Sub)
tempThread.Start()
Me.TextBoxAccuracy.Enabled = False
Me.TextBoxMaxIteration.Enabled = False
Me.OptimizationStatusUpdate()
<br>
Optimization
<br>
Private Sub OptimizationStatusUpdate()
Dim tempThread As New Threading.Thread(Sub()
Dim attempt As Integer = 0
Dim firstRun As Boolean = True
While True
If Me.optimizationEngineField.IsRunning Then
firstRun = False
Me.BeginInvoke(Sub()
Me.TextBoxStatus.Text = Me.optimizationEngineField.Status
Me.TextBoxIsRunning.Text = Me.optimizationEngineField.IsRunning
Me.TextBoxIterationNumber.Text = Me.optimizationEngineField.IterationNumber
Me.TextBoxPercentError.Text = Me.optimizationEngineField.PercentError
Me.TextBoxActiveAntCount.Text = Me.optimizationEngineField.ActiveAntCount
Me.TextBoxAggregatedAntCount.Text = Me.optimizationEngineField.aggregatedAntCount
End Sub)
Else
If Not Me.optimizationEngineField.IsRunning And firstRun = False Then
attempt = attempt + 1
End If
If attempt >= 5 Then
Exit While
End If
End If
Threading.Thread.Sleep(1000)
End While
Me.BeginInvoke(Sub()
Me.ButtonSaveResults.Text = "Save Results"
Me.ButtonSaveResults.Enabled = True
Me.TextBoxIsRunning.Text = "False"
Me.Run.Enabled = True
Me.Run.Text = "Run"
Me.simphony.Enabled = True
Me.access.Enabled = True
End Sub)
End Sub)
tempThread.Start()
End Sub
<br>
I searched a lot in net and First of all : all pages approximately have been written for win apps and they are not for web , If I am not wrong and secondly : I Try to convert those codes from C# to VB and got some errors How can I change Optimization Code to run on Web ?
Thanks
Upvotes: 0
Views: 107