Well, one thing to consider might be that calling directly into your form's code from somewhere else might not be the best overall program structure here. You might think about instead creating a class that does your event log writing and raises its own events, then have the form own an object of that type and subscribe to its events.
However, while that might provide a cleaner separation of concerns, you still would need to solve the problem you have here. It isn't the event call itself that causes the trouble, it is that updating a winforms control (as you do inside the event handler) is not a thread-safe operation. A control can only be updated safely from within the thread that created and owns the control. Luckily, there is a way provided to ask the form's control thread to do the work of calling a specified method itself, using the
Invoke
method.
I believe what you want is something like this in the form's code:
Delegate Sub textUpdater(newText as String)
Public Sub updateTextBox1(newText As String)
If Me.TextBox1.InvokeRequired Then
Me.Invoke(New textUpdater(AddressOf updateTextBox1), newText)
Else
TextBox1.Text = newText
End If
End Sub
Private Sub Eventlog_changed(ByVal sender As Object, ByVal e As EventLogArgs)
updateTextBox1(e.GetEntries())
End Sub
What we've got here is a method (
updateTextBox1
) which can now safely be executed from any thread. If it is being called from the form's own control thread, it just updates the text box. If it is not, it hands its own address to the form's control thread using
Invoke
so the same function will be called again, this time from the proper thread.