Re: Populate an ImageList from another thread
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Sat, 15 Dec 2007 11:40:10 -0800
On Sat, 15 Dec 2007 11:12:15 -0800, Greg Cadmes <gcadmes@xxxxxxxxx> wrote:
Becase your listview was created by your form's gui thread, by saying
Control.Invoke
is the same as ListView.Items.Add.... syncrhonously. The calling
thread still needs to wait for the Invoke() function to complete until
the control is returned to the calling thread.
Yes, it is a synchronous call. But as long as the main GUI thread isn't waiting on the thread that is trying to make the synchronous call, it's not a problem.
Conversely, if it _is_ a problem to make the synchronous call, then there is an underlying problem with the design of the code that is likely fixed in a better way. There are good reasons to use BeginInvoke() instead of Invoke(), but working around a deadlocking design bug isn't one of them.
If you look at the sample code I provided to the OP (contrary to your apparent misunderstanding, I'm not the OP, nor do I have code that isn't working correctly), it is quite possible and reasonable to use Invoke() rather than BeginInvoke().
This is not a .NET bug.
You don't know that. There's no way for you to know that, because you haven't seen the code that doesn't work, and neither have I.
Furthermore, the fact that code that is known to be correct (see the sample I posted) apparently does not work on the OP's installation suggests that at the very least, there's something wrong with his installation. And it may well be that whatever's wrong with his installation is simply due to the specific version he has, and that there is indeed a bug in that version of .NET.
I use the APM (Asynchronous Programming Model)
in almost every project I work on.
Take a look at this example of asynchronous method invocation:
https://secure.codeproject.com/KB/cs/AsyncMethodInvocation.aspx
I'm sure you'll see that this is the right approach for the creating
the tiled bitmaps.
While I'm very familiar with asynchronous programming, both in the context of .NET and without, I disagree that this particular situation is one in which using an asynchronous invoke is required or even desirable.
In situations where there _is_ some kind of potential deadlock problem, switching to BeginInvoke() typically results in all of the operations being queued up until some later time. Because it's a situation that otherwise would deadlock, that "later time" usually winds up being "not until the background thread has completed its work", which means that those updates all come at once, after the background thread is done.
In other words, using BeginInvoke() winds up accomplishing pretty much the same thing that would happen as if the work were all done synchronously in the main thread.
Now, I don't know about you, but IMHO it doesn't really make much sense to use a background worker thread when the net effect winds up being identical to that had one just done everything synchronously in the main GUI thread. That's a pointless use of background worker threads.
Pete
.
- Follow-Ups:
- Re: Populate an ImageList from another thread
- From: Greg Cadmes
- Re: Populate an ImageList from another thread
- References:
- Populate an ImageList from another thread
- From: Paul E Collins
- Re: Populate an ImageList from another thread
- From: Greg Cadmes
- Re: Populate an ImageList from another thread
- From: Peter Duniho
- Re: Populate an ImageList from another thread
- From: Greg Cadmes
- Populate an ImageList from another thread
- Prev by Date: Re: Populate an ImageList from another thread
- Next by Date: How to get help when working offline
- Previous by thread: Re: Populate an ImageList from another thread
- Next by thread: Re: Populate an ImageList from another thread
- Index(es):
Relevant Pages
|