Can someone please help me with the following problem:
There are two classes MainForm and LWriter. Below is the LWriter method, which, in addition to writing to a file, sends some updates to the RichTextBox control (via mainForm.UpdateLog (text)). Everything works fine, however this WriteOutput method also does some extensive processing, which freezes the form during calculation.
I think WriteOutput should be encapsulated in a separate thread. Can someone please help me explain how to put WriteOutput (LWriter class) in a thread that will then call mainForm.UpdateLog () from mainFrom in a safe way?
I am new to threads, so help would be greatly appreciated.
public void WriteOutput(string output, Links[] links) { try { using (StreamWriter sw = new StreamWriter(output)) { for (int x= 1; x<links.Length;x++) { ... sw.WriteLine( ... ); sw.Flush(); } mainForm.UpdateLog(<text>); } } catch(Exception e) { ... } }
source share