Hi,
I am a new with C# and I am trying to design a form that could be updated by a background worker thread. The data are coming from a file and are supposed to be outputed to a textbox and it supposed to be a continuous streaming output.
I have a problem now updating my form. When I start the update using OnDisconnect(button), the GUI freezes.
Is that something I am doing wrong with the code below. Can anyone help me please? Maybe with an example of code that can cleary show how a GUI can be updated from a file?
Thanks in advance for your help.
Yannicko
---------------------------------------------------------------------------------------
csharp
protected virtual void OnDisconnect (object sender, System.EventArgs e)
{
bw = new BackgroundWorker();
bw.DoWork += bw_DoWork;
bw.RunWorkerAsync ("A test message to the worker");
}
protected virtual void bw_DoWork (object sender, DoWorkEventArgs e)
{
// This is called on the worker thread
Console.WriteLine (e.Argument);
Stream fsIn1 = new FileStream(@"/var/log/test",FileMode.Open, FileAccess.Read);
BufferedStream fileBuffer=new BufferedStream(fsIn1);
byte[] buff;
string buffer;
StringBuilder mybuf = new StringBuilder();
int BytesRead;
bool readMore=true;
BytesRead=fsIn1.ReadByte();
while(BytesRead!=0)
{
while((char)BytesRead!='\n' || BytesRead!=0)
{
BytesRead=fsIn1.ReadByte();
MainText.Buffer.Text+=(char)ReadByte().ToString;
string.Concat(aText, (char)BytesRead);
Console.Write(aText);
}
//bw.Disposed(object sender, EvenArgs e);
}
fsIn1.Close();
}
*edit: Please use code tags in the future, thanks!
This post has been edited by Martyr2: 13 Jul, 2008 - 10:13 PM