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
| '---- version avec un Thread ----
Private ThreadGenerer As System.Threading.Thread
Private Sub StartThread()
ThreadGenerer = New Threading.Thread(AddressOf GenererFichierPhrases)
ThreadGenerer.Start()
End Sub
'---- Version avec un backgroundworker ----
Private Sub btnVoca_bdMAJ_Click(sender As Object, e As EventArgs) Handles btnVoca_bdMAJ.Click
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork
GenererFichierPhrases()
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
MsgBox("Mise à jour terminée.")
End Sub
Public Function GenererFichierPhrases()
Dim notepad As Process = New Process()
notepad.StartInfo.FileName = "Notepad.exe"
notepad.StartInfo.UseShellExecute = False
notepad.StartInfo.RedirectStandardInput = True
notepad.Start()
notepad.WaitForInputIdle()
OuvrirConnection()
Dim Select_cmd As New SQLiteCommand("Select * FROM Phrases order by RANDOM() LIMIT 15")
Select_cmd.Connection = ObjetConnection
Dim reader As SQLiteDataReader = Select_cmd.ExecuteReader()
If notepad.Responding Then
Do While reader.Read
Dim maLigne As String = reader.Item("Phrase_ES") & vbCrLf &
reader.Item("Phrase_FR") & vbCrLf
System.Windows.Forms.SendKeys.SendWait(maLigne)
Loop
End If
FermerConnection()
notepad.Close()
End Function |
Partager