Solved

Threading problems, not working

Posted on 2004-08-01
2
208 Views
Last Modified: 2010-04-15
HI,

I need to read a large file, and find certain words in the file, then list them in a listview.

I can do it, but the problem is that it has to read the whole file before it updates the listview. I need to to update the listview as it reads the file, ie. one addition at a time, while it is also continues to read the file. I added the basic functions that I am using, not the full code, but you should be able to see what I am doing for the code below.

t = new Thread(new ThreadStart(Add_Words));
t.Start();

//Words is a property that gets the search words

//This is in a function that reads the file
while((str = reader.ReadLine()) != null)
{
link=str;
if (str.IndexOf(search_word) > 0)
{
this.Words = s;
//I truncate the string to get only the word
Add_Words();
}
}

private void Add_Words()
{
item = new ListViewItem(this.Words);
lst_words.Items.Add(item);
}
0
Comment
Question by:unomateo
  • 2
2 Comments
 
LVL 10

Accepted Solution

by:
smegghead earned 125 total points
ID: 11687593
You have to invoke the call to Add_Words..

All calls to the GUI must be done on the main thread.

So..

Create a delegate for a method with no parameters

      private delegate void CallUpdate();

then, rather than calling Add_Words();  

do the following

      this.Invoke(new CallUpdate(Add_Words));

Smg.
0
 
LVL 10

Expert Comment

by:smegghead
ID: 11687594
Also, you might want to do a 'Refresh' on the control after adding each entry.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now