473,387 Members | 3,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Threads Question - updating UI

I'm new to all this so please forgive me if I use the wrong terms or have
used the wrong approach here...

I have a thread which gathers some information from the internet for my
windows application. It gathers the information fine, but I am having a
problem when trying to display it.

The information is being diplayed in a datagrid, and has about 100 rows.
When the thread throws an "Information Has Been Gathered" event (which would
essentially be just before the thread has finished) to my main windows app I
try to display the information passed in the datagrid.

However, the main program throws a 'null exception' at fairly random points
during the populating of the datagrid. Sometimes it may throw it whilst
displaying row 47, sometimes at row 22, etc.. It seems to me that the thread
is finishing before it can complete the UI displaying tasks in the
"Information Has Been Gathered" event handler routine. I have tried just
getting it to diplay a couple of lines and it works ok.

The only way I can get it to work is if I tell the main application to wait
for the thread (i.e. thread1.join) before populating the datagrid. This is
clearly what I didn't want to do as the program then freezes until the
thread has finished.

How should I do this? Am I using the right approach? Should I try using a
delegate to update the UI from the thread, or will this still not solve the
problem? (not used delegates before so new ground for me again)

TIA

Jan 19 '06 #1
2 1018

Have a look at Ted Pattison's articles in MSDN Magazine about threads,
delegates and updating the UI
http://msdn.microsoft.com/msdnmag/fi...on&words=exact
Basic Instincts, January 2004
Basic Instincts, May 2004
Basic Instincts, June 2004
Basic Instincts, September 2004
hth,
Alan.

Jan 19 '06 #2
Thanks Alan - excellent articles. Nearly understand what I'm doing now.
I'll keep at it.

<al*******@users.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...

Have a look at Ted Pattison's articles in MSDN Magazine about threads,
delegates and updating the UI
http://msdn.microsoft.com/msdnmag/fi...on&words=exact
Basic Instincts, January 2004
Basic Instincts, May 2004
Basic Instincts, June 2004
Basic Instincts, September 2004
hth,
Alan.

Jan 19 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: perchef | last post by:
Hi, I have several files to download and a GUI to update. I know this is a frequently asked question but i can't find an appropriate solution. My Downloader extends threading.Thread and update a...
6
by: m | last post by:
Hello, I have an application that processes thousands of files each day. The filenames and various related file information is retrieved, related filenames are associate and placed in a linked...
12
by: Joey Powell | last post by:
Re: Original post = Windows forms - how do I get them to render/update properly? from August 22. Okay I am making some progress with being able to use delegates to run my shelled processes on...
22
by: Jeff Louie | last post by:
Well I wonder if my old brain can handle threading. Dose this code look reasonable. Regards, Jeff using System; using System.Diagnostics; using System.IO; using System.Threading;
12
by: Grant | last post by:
I am having great difficulty understanding this and any code samples I find online are kilometres long and complicated to understand...Please could someone give me a simple exampe of how to get a...
1
by: andreas.baus | last post by:
Hi. I'm trying to figure out how to properly start and stop threads from a windows form. One thing I still have a problem with is how to make sure the spawned thread(s) are shut down when the...
16
by: Thirsty Traveler | last post by:
I would like to create a test harness that simulates multiple concurrent users executing an individual thread. I would like this to be determined at runtime when the user specifies the number of...
0
by: Kate77 | last post by:
Hi, I have another question, I try to make my threads updating the form, it works fine, for the first thread , but afterwards its not updating the labels on the form anymore not from inside...
3
by: Charlie Brown | last post by:
I have an application that loops through a dataset and retrieves / updates information in rows that meet certain criteria. When the end user clicks a button, the dataset is then merged with the...
1
by: Peter | last post by:
Hi, I have a Dictionary<key, valuewhich is accessed by three threads. One thread puts my value objects in the dictionary (occasionally), and also updates the contents of existing value objects -...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.