If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Threading UI components

I'm building a WPF photo viewing application, and trying to get a handle on threading. I've asked about this before in this forum -- and although everyone's reading suggestions have been good, I'm still having a hard time putting everything together.

I have two listBoxes -- gallerySelector stores a the names of folders with which images are stored. PhotosListBox is populated with the photos in the directory specified by gallerySelector.

I want to make the gallerySelector more responsive (so you can arrow up and down through all the folders very quickly -- without having to wait for PhotosListBox to load alll the images), so I thought I'd try threading once again. But I'm failing miserably. Of course, I'm getting the following error message:

Code:

"The calling thread cannot access this object because a different thread owns it."

Would it work better to move the threading code into the ObservableClass definition? In addition, it would be great to populate the PhotosListBox item-by-item, so they would be inserted into the PhotosListBox as they are loaded and rendered.

I'll be ecstatic if I can get this working -- I appreciate any help anyone can give me. Thanks!

Everything works dandy, but if I switch between directories before the thread finishes executing, it will clear the list box, but the (not finished yet) thread continues to populate it with images from the LAST directory.

So, I tried to declare the thread (instead of just new Thread()) so I could manipulate it later using Start() and Abort(), like this:

Re: Threading UI components

It's not good to ABORT a thread, unless you have to. Just raise an event on the change event, and set a boolean in the loop. if threadRunning = True

*looks embarrassed* Yeah, I should have thought of that, shouldn't have I?

Haha, how obvious is it that I'm an Electrical Engineering student who hasn't taken a programming class since Freshman year?

Anyway, next question: if it's not a good idea to abort a thread, then how should I stop it? Can I send it a message to stop inserting images into the listbox if I switch directories? Looking at my code, what's the easiest way to implement that?

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.