Hallo,
ich nutze einen Backroundworker um per Ping zu ermitteln ob 2 Geräte im Netzwerk vorhanden sind.
In diesem Worker aktualisiere ich Label, Textboxe oder auch eine Listbox.
Public Delegate Sub SetTextBoxDelegate(ByVal TB As TextBox, ByVal txt As String)
Public Delegate Sub SetLabelTextDelegate(ByVal LBL As Label, txt As String)
Public Delegate Sub InsertListBoxItemDelegate(ByVal LB As ListBox, txt As _
String)
Public Sub SetTextBox(ByVal TB As TextBox, ByVal txt As String)
If TB.InvokeRequired Then
TB.Invoke(New SetTextBoxDelegate(AddressOf SetTextBox), New Object( _
) {TB, txt})
Else
TB.AppendText(txt)
End If
End Sub
Public Sub SetLabelText(ByVal LBL As Label, ByVal txt As String)
If LBL.InvokeRequired Then
LBL.Invoke(New SetLabelTextDelegate(AddressOf SetLabelText), New _
Object() {LBL, txt})
Else
LBL.Text = txt
End If
End Sub
Public Sub InsertListBoxItem(ByVal LB As ListBox, ByVal txt As String)
If LB.InvokeRequired Then
LB.Invoke(New InsertListBoxItemDelegate(AddressOf Me.InsertListBoxItem), New _
Object() {LB, txt})
Else
LB.Items.Insert(0, txt)
End If
End Sub Das tut auch alles soweit.
Ich habe noch eine Funktion in einer anderen Klasse welche mir einen Eintrag in ein Logfile erstellt.
Diese Funktion übernimmt eigentlich auch das aktualisieren der Listbox.
Public Class FileFunctions
Public Sub SaveSystemStatusLogFile(ByRef DateiInhalt As String)
Dim Pfad As String = Application.StartupPath & "\LogFiles\"
Dim Dateiname As String = Date.Today() & "-" & "SystemStatus" & ".log"
Dim STR_Senderichtung As String = ""
Dim thisTime As String
thisTime = Format(Now, "HH:mm:ss.fff")
If IO.Directory.Exists(Pfad) = True Then
IO.File.AppendAllText(Pfad & Dateiname, thisTime & " - " & DateiInhalt _
+ Environment.NewLine)
Else
IO.Directory.CreateDirectory(Pfad)
IO.File.AppendAllText(Pfad & Dateiname, thisTime & " - " & DateiInhalt _
+ Environment.NewLine)
End If
Main.InsertListBoxItem(Main.ListBox_SystemStatus, thisTime & " - " & _
DateiInhalt)
End Sub
End Class Aus dem Backroundworker heraus wird zwar der Logfile-Eintrag erzeugt, nicht aber der Listbox-Eintrag.
Möchte ich den Listox-Eintrag vor dem Logfile machen, wird sogar der Logfile Eintrag nicht mehr gemacht, sprich die Sub abgebrochen.
Wo habe ich da meinen Gedankenfehler?
Beitrag wurde zuletzt am 19.12.15 um 12:19:08 editiert. |