Home > Net >  C # Winform how to implement the log information real-time display in the form of textbx?
C # Winform how to implement the log information real-time display in the form of textbx?

Time:03-20



The form code:
Public partial class MainFrame: Form
{
Private static XmlDocument xmlDoc=new XmlDocument ();

Public MainFrame ()
{
InitializeComponent ();
}
GetTime dt=new GetTime ();

Public void the start ()
{
ReadLog (" System Start Running... \n");
ReadLog (" database connection success... \n");
AutoProcessThread autopt=new AutoProcessThread ();
The Thread of td=new Thread (autopt. Run);
//run a method of cs file
Td. Start ();
}
Public void readLog (string log)
{
String time=dt. DateTime ();
TextBox1. AppendText (time + log + "\ n");
}
}
}

The class AutoProcessThread
{
Public void the run ()
{
MainFrame mf=new MainFrame ();
Mf. ReadLog (" enter autoProcess -- -- -- -- -- - run ");
}
}


So the question comes, why call readLog method can display in the form in the textBox, while other cs file called mf. ReadLog (" enter autoProcess -- -- -- -- -- - run ") are not shown on the textBox form?

CodePudding user response:

Someone give you a answer

CodePudding user response:

Since you have no showDialog,

The class AutoProcessThread
{
Public void the run ()
{
MainFrame mf=new MainFrame ();
Mf. ReadLog (" enter autoProcess -- -- -- -- -- - run ");
mf. ShowDialog ();
}
}

CodePudding user response:

Log is not much, just do a timer brush,
String s=File. ReadAllText (log filename);
If (s!=textBox1. Text)
TextBox1. Text=s;

CodePudding user response:

reference cruise worship in one thousand on the second floor response:
since you have no showDialog,

The class AutoProcessThread
{
Public void the run ()
{
MainFrame mf=new MainFrame ();
Mf. ReadLog (" enter autoProcess -- -- -- -- -- - run ");
mf. ShowDialog ();
}
}
boy directly into an infinite loop in the popup window

CodePudding user response:


 
Public void readLog (string log)
{
String time=dt. DateTime ();
This. Invoke (new Action (()=& gt;
{
TextBox1. AppendText (time + log + "\ n");
}));
}
  •  Tags:  
  • C#
  • Related