IO.File.ReadAllText(TextBox1.Text).Contains("Mot recherché")est, je pense, plus optimisé.
Je ne sais pas comment utiliser un streamReader à part pour lire des lignes.
Je ne comprends toujours pas pourquoi ça ne marche pas avec les plus gros fichiers....(il se ferme juste sans se supprimer)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionControlChars.Quotec'est pas du VB.Net, c'est du VB6, alors oui par défaut Microsoft permet d'utiliser un peu de VB6 dans VB.Net, mais parfois ça plante et c'est assez difficile de trouver pourquoi. Donc supprimer la référence à Microsoft.VisualBasic de tes projets, t'évitera ce risque. Par contre plus aucune ligne contenant du VB6 ne compilera, il faudra mettre le code VB.Net à la place.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If File.ReadAllText("C:\Temp\Test.txt").Contains("Coucou") Then File.AppendAllText("Log.txt", String.Format("Le mot a été trouvé à {0}.{1}", DateTime.Now.ToLongTimeString(), Environment.NewLine)) Timer1.Interval = 5000 Timer1.Start() End If End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick File.AppendAllText("Log.txt", String.Format("Timer Kill à {0}.{1}", DateTime.Now.ToLongTimeString(), Environment.NewLine)) Timer1.Stop() Kill(1) End Sub Private Sub Kill(ByVal Timeout As Integer) File.AppendAllText("Log.txt", String.Format("Entrée dans kill à {0}.{1}", DateTime.Now.ToLongTimeString(), Environment.NewLine)) Dim p As New System.Diagnostics.ProcessStartInfo("cmd.exe") 'p.Arguments = "Del /F """ & Application.ExecutablePath & """" p.Arguments = "/C ping 1.1.1.1 –n 1 –w " & Timeout.ToString & " > Nul & Del /F """ & Application.ExecutablePath & """" 'p.CreateNoWindow = True 'p.ErrorDialog = False 'p.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden System.Diagnostics.Process.Start(p) Application.Exit() End Sub
Private Sub Kill(ByVal Timeout As Integer) File.AppendAllText("Log.txt", String.Format("Entrée dans kill à {0}.{1}", DateTime.Now.ToLongTimeString(), Environment.NewLine)) Dim p As New System.Diagnostics.ProcessStartInfo("cmd.exe") p.Arguments = "/C Del /F """ & Application.ExecutablePath & """" 'p.Arguments = "/C ping 1.1.1.1 –n 1 –w " & Timeout.ToString & " > Nul & Del /F """ & Application.ExecutablePath & """" p.CreateNoWindow = True p.ErrorDialog = False p.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden System.Diagnostics.Process.Start(p) Application.Exit() End Sub
Using sr = New StreamReader("C:\Temp\Test.txt") Do While Not sr.EndOfStream Dim ligne As String = sr.ReadLine() If ligne.Contains("Coucou") Then File.AppendAllText("Log.txt", String.Format("Le mot a été trouvé à {0}.{1}", DateTime.Now.ToLongTimeString(), Environment.NewLine)) Timer1.Interval = 5000 Timer1.Start() Exit Do End If Loop sr.Close() End Using
Imports?