?
Solved

Threading problems, not working

Posted on 2004-08-01
2
Medium Priority
?
214 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 10

Accepted Solution

by:
smegghead earned 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

765 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