Get 20M+ Full-Text Papers For Less Than $1.50/day. Start a 14-Day Trial for You or Your Team.

Learn More →

A Programmer’s Introduction to C# 2.0DiskDiff: More Sophistication

A Programmer’s Introduction to C# 2.0: DiskDiff: More Sophistication CHAPTER 36 ■ ■ ■ Now that the basic outline of your DiskDiff application is done, it’s time to make it better. Populating on a Thread To make your application behave, you need to do the scan on a different thread so the user- interface thread can continue operating. In this example, you’ll use the Thread object from the System.Threading namespace. Starting the thread is easy: public void Populate() Thread t = new Thread(new ThreadStart(DoPopulate)); t.Start(); The function that will be called at the start of the thread is DoPopulate(). To create a new thread, a ThreadStart delegate must be created on the function you want called and passed to the thread. Then, the Start() member on the thread is called, and the thread starts and runs on its merry way. That gets the process working, but your app is now broken. When the DoTree() function in the form calls Populate(), it will start the thread and return immediately and then try to repaint the tree form. This is bad, because the information isn’t ready to paint yet. To fix this, you’ll add a new event to the DirectoryNode object for when the populate function is done: void DoPopulate() http://www.deepdyve.com/assets/images/DeepDyve-Logo-lg.png

A Programmer’s Introduction to C# 2.0DiskDiff: More Sophistication

Editors: Gunnerson, Eric; Wienholt, Nick

Loading next page...
 
/lp/springer-journals/a-programmer-s-introduction-to-c-2-0-diskdiff-more-sophistication-QwislctZPg
Publisher
Apress
Copyright
© Apress 2005
ISBN
978-1-59059-501-5
Pages
417 –429
DOI
10.1007/978-1-4302-0035-2_36
Publisher site
See Chapter on Publisher Site

Abstract

CHAPTER 36 ■ ■ ■ Now that the basic outline of your DiskDiff application is done, it’s time to make it better. Populating on a Thread To make your application behave, you need to do the scan on a different thread so the user- interface thread can continue operating. In this example, you’ll use the Thread object from the System.Threading namespace. Starting the thread is easy: public void Populate() Thread t = new Thread(new ThreadStart(DoPopulate)); t.Start(); The function that will be called at the start of the thread is DoPopulate(). To create a new thread, a ThreadStart delegate must be created on the function you want called and passed to the thread. Then, the Start() member on the thread is called, and the thread starts and runs on its merry way. That gets the process working, but your app is now broken. When the DoTree() function in the form calls Populate(), it will start the thread and return immediately and then try to repaint the tree form. This is bad, because the information isn’t ready to paint yet. To fix this, you’ll add a new event to the DirectoryNode object for when the populate function is done: void DoPopulate()

Published: Jan 1, 2005

Keywords: File Object; Event Handler; Tree View; Object Node; Full Path

There are no references for this article.