Understanding the use of Control.Invoke

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a very amatuerish question that hopefully someone can help me out
with. I have an application that unpredictably hangs/locks on occasion.
After scouring the newsgroups, it seems very clear that I must be improperly
multithreading or updating controls. Where I get confused, is that no where
in my app do I knowingly create threads (basically because I dont know how to
use them)! Would using global variables to pass from form to form be
considered a reason the application is locking and therefore a place to use
Control.Invoke?

Thanks!
 
Do you use a Threading.Timer or the ThreadPool (search the project for
"Threading")?
Do you use any 3rd party controls or a component from opennetcf (e.g.
SerialPort)?

Cheers
Daniel
 
Daniel,

Actually, I have several apps and they all seem to lock up on occasion. So
I am obviously making the same mistake repeatedly. To answer your question
about threads, yes I do find Threading when I search my project(s) but
basically that is because I implemented a 'ControlInvoker' class I found via
the web. I did this because of my hunch that I was causing my app to hang by
populating controls on my form via global variables. But, I can guarauntee
you that my app(s) were hanging before there was ever any mention of a
thread. And yes, I do use 3rd party controls on occasion (but not in all my
apps) including a serial control. Think that could be the cause?

Thanks,
Mike
 
Globals and forms etc are likely irrelevant. If you don't know if you need
ControlInvoker there is no point using it... in my opinion.

Apart from ControlInvoker, do you have other references to Threading?

Do the 3rd party controls you use raise any events that you handle? If yes,
they could be on a different thread so if you touch UI controls from your
event handler the problem will appear (and the solution would be to use
Control.Invoke from the event handler).

Without telling us what controls you are using or posting a repro there is
not much else I can add...

Cheers
Daniel
 
Back
Top