Solved

Threading problems, not working

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

685 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