[quoted text, click to view] > Im building a multithreaded application which uses forms and im
> having some problems possibly due to my inexperience.
I have given up on 99% of the Invoke game. I keep my gui thread and my
worker threads isolated from each other. Worker threads enqueue results
(objects) on a thread-safe queue. The gui thread dequeues them for action at
its leisure. The dequeuing takes place in a timer tick event that is
normally at a slow burn rate, say one tick every 10 seconds. The enqueuing
mechanism sets the timer interval to 1 millisecond via Invoke (the remaining
1% is here). When the queue goes empty, the gui thread increases the
interval.
It is polling (gui thread dequeues when it wants to) with a demand wakeup
(timer interval). Very low tech. The gain is no multi-thread issues,
problems, or whatever. None, and I really mean it. I have not addressed the
area of a worker querying the gui for info that requires marshalling, so I
have nothing to say about that.
You probably didn't want to hear this, and I'm sorry about that. In the
past, I have had multi-thread problems like yours, and under pressure to make
progress, I settled on the queue solution. Since this approach precludes
marshalled calls between threads, I have to think through multi-threaded
designs with some care, and when I paint myself into a corner, I have to
resist the temptation to make a marshalled call. I don't find these
limitations onerous.
I know that what I do is out of the mainstream. Also, I don't urge you to
move in one direction or another. I'm just saying my bit re multi-threading
problems in general and I'm suggesting an alternative. Good luck.