1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
Public Class FibonacciForm
Inherits System.Windows.Forms.Form
'
'
Private TotalEl As Integer = 0
Private Cancel As Boolean = False
Private numberToCompute As Integer = 0
Private highestPercentageReached As Integer = 0
Private connexion As New SqlConnection
Private instanceNameProp As String
Private numericUpDown1 As System.Windows.Forms.NumericUpDown
Private WithEvents startAsyncButton As System.Windows.Forms.Button
Private WithEvents cancelAsyncButton As System.Windows.Forms.Button
Private progressBar1 As System.Windows.Forms.ProgressBar
Private resultLabel As System.Windows.Forms.Label
Private ListBox1 As System.Windows.Forms.ListBox
Private WithEvents backgroundWorker1 As System.ComponentModel.BackgroundWorker
Public Sub New()
InitializeComponent()
End Sub 'New
Private Sub startAsyncButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startAsyncButton.Click
' Reset the text in the result label.
resultLabel.Text = [String].Empty
' Disable the UpDown control until
' the asynchronous operation is done.
Me.numericUpDown1.Enabled = False
numericUpDown1.Value = NbElement()
resultLabel.Text = "0/" & NbElement()
' Disable the Start button until
' the asynchronous operation is done.
Me.startAsyncButton.Enabled = False
' Enable the Cancel button while
' the asynchronous operation runs.
Me.cancelAsyncButton.Enabled = True
' Get the value from the UpDown control.
numberToCompute = CInt(numericUpDown1.Value)
' Reset the variable for percentage tracking.
highestPercentageReached = 0
' Start the asynchronous operation.
backgroundWorker1.RunWorkerAsync(numberToCompute)
End Sub
Private Sub cancelAsyncButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cancelAsyncButton.Click
Cancel = True
' Cancel the asynchronous operation.
' Disable the Cancel button.
cancelAsyncButton.Enabled = False
End Sub 'cancelAsyncButton_Click
' This event handler is where the actual work is done.
Private Sub backgroundWorker1_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) Handles backgroundWorker1.DoWork
' Get the BackgroundWorker object that raised this event.
Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
' Assign the result of the computation
' to the Result property of the DoWorkEventArgs
' object. This is will be available to the
' RunWorkerCompleted eventhandler.
''
e.Result = ComputeFibonacci(e.Argument, worker, e)
''
End Sub 'backgroundWorker1_DoWork
' This event handler deals with the results of the
' background operation.
Private Sub backgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Handles backgroundWorker1.RunWorkerCompleted
' First, handle the case where an exception was thrown.
If (e.Error IsNot Nothing) Then
MessageBox.Show(e.Error.Message)
ElseIf e.Cancelled Then
' Next, handle the case where the user canceled the
' operation.
' Note that due to a race condition in
' the DoWork event handler, the Cancelled
' flag may not have been set, even though
' CancelAsync was called.
resultLabel.Text = "Canceled"
Else
' Finally, handle the case where the operation succeeded.
resultLabel.Text = e.Result.ToString()
End If
' Enable the UpDown control.
Me.numericUpDown1.Enabled = True
' Enable the Start button.
startAsyncButton.Enabled = True
' Disable the Cancel button.
cancelAsyncButton.Enabled = False
End Sub 'backgroundWorker1_RunWorkerCompleted
' This event handler updates the progress bar.
Private Sub backgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs) Handles backgroundWorker1.ProgressChanged
'
GalaxyConnection()
'
FrmMain.Exporter.Enabled = True
Module1.connection_travail(connexion)
Try
Dim strRequeteLocation As String = "Exec CREATE_PROP"
Dim oCommandLocation As New SqlCommand(strRequeteLocation, connexion)
Dim MyExecut As SqlDataReader
MyExecut = oCommandLocation.ExecuteReader()
While MyExecut.Read()
Dim tagnames As String() = {"$IB_Property"}
Dim queryResult As IgObjects = galaxy.QueryObjectsByName(EgObjectIsTemplateOrInstance.gObjectIsTemplate, tagnames)
Dim userDefined As ITemplate = DirectCast(queryResult(1), ITemplate)
'Prop
instanceNameProp = [String].Format("$" + MyExecut(1))
'création Prop
sampleinstProp = userDefined.CreateTemplate(instanceNameProp, True)
ListBox1.Items.Add("Création de : " & instanceNameProp)
'progressBar1.Value = progressBar1.Value + 1
Me.progressBar1.Value = e.ProgressPercentage
ListBox1.SetSelected(progressBar1.Value - 1, True)
resultLabel.Text = progressBar1.Value & "/" & TotalEl
If (Cancel) Then
Me.backgroundWorker1.CancelAsync()
End If
End While
MyExecut.Close()
Catch ex As Exception
MsgBox("Arrêt du transfert ! " & ex.Message)
End Try
connexion.Close()
End Sub
' This is the method that does the actual work. For this
' example, it computes a Fibonacci number and
' reports progress as it does its work.
Function ComputeFibonacci(ByVal n As Integer, ByVal worker As BackgroundWorker, ByVal e As DoWorkEventArgs) As Long
' The parameter n must be >= 0 and <= 5000.
' Fib(n), with n > 5000, overflows a long.
If n < 0 OrElse n > 5000 Then
Throw New ArgumentException("value must be >= 0 and <= 5000", "n")
End If
Dim result As Long = 0
' Abort the operation if the user has canceled.
' Note that a call to CancelAsync may have set
' CancellationPending to true just after the
' last invocation of this method exits, so this
' code will not have the opportunity to set the
' DoWorkEventArgs.Cancel flag to true. This means
' that RunWorkerCompletedEventArgs.Cancelled will
' not be set to true in your RunWorkerCompleted
' event handler. This is a race condition.
If worker.CancellationPending Then
e.Cancel = True
Else
If n < 2 Then
result = 1
Else
result = ComputeFibonacci(n - 1, worker, e) + ComputeFibonacci(n - 2, worker, e)
End If
' Report progress as a percentage of the total task.
Dim percentComplete As Integer = CSng(n) / CSng(numberToCompute) * 100
If percentComplete > highestPercentageReached Then
highestPercentageReached = percentComplete
worker.ReportProgress(percentComplete)
End If
End If
Return result
End Function
<STAThread()> Shared Sub Main()
Application.Run(New FibonacciForm)
End Sub 'Main
End Class 'FibonacciForm |