Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 117,542 C# Programmers for FREE! Ask your question and get quick answers from experts. There are 1,667 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Updating buffer with background worker

 
Reply to this topicStart new topic

Updating buffer with background worker

Yannicko
post 13 Jul, 2008 - 09:57 PM
Post #1


New D.I.C Head

*
Joined: 13 Jul, 2008
Posts: 1

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! code.gif

This post has been edited by Martyr2: 13 Jul, 2008 - 10:13 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/7/08 05:33PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month