I know that regarding this problem there are many questions and also many answers, but I am reading since days and cannot find a solution for my problem. I should also mention that I am beginner in this matter.
First of all I want to explain in text what my vb.net program does:
- After starting my app with a button, I start a filewatcher for a status message file on the MainForm and I start a new thread for calculating my testdata.
- This thread initiates a class and within this class it initiates a filewatcher too.
- When testdata are created in the monitored folder, the thread analyses my data and writes it to a database.
- Within the calculation and after writing to the database the task writes some status messages to the status message file.
- The content of the status messages should be shown on the MainForm within a textbox and should update always when a new status was written, so that the newest status is always on top of the TextBox. Also the progress has to be reported to the MainForm in order to be shown with a progressbar.
- This is repeating as long as I have new testdata in my folder, in other words is my app a "data vacuum cleaner" which sucks all the data from the monitored directory in order to analyse and to write it to a database. If all the data in the folder is analysed and written to the database, it waits for new data and after the filewatcher fired a new event, the task starts analysing and writing again. So I dont start a Task always when I have new data. The task is started only when I start my app. The rest is done by the filewatcher event within this task.
I am not able to do that because I can't modify my GUI from this thread. I should also mention, that the code for this thread is in another class.
This is my code on the main form:
Private Async Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
Await Task.Run(Sub() gFileWatcher.InitWatcher())
End Sub
How is it possible to refresh the TextBox in realtime, I mean after status has changed?