Solved

Threading problems, not working

Posted on 2004-08-01
2
212 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 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Where does legacy ASP.NET initialize language? 2 97
How to repeat the data 4 41
Unlocking a column in excel using C# 17 32
Selenium and Xpath 4 65
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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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