On Mon, 21 May 2007 21:43:48 -0700, dk60 <dannykotlar@gmail.comwrote:
Quote:
Thanks,
first, I am using VS 2005 and didn't get an error.
Hmmm...well, maybe I misunderstand how the ShowDialog() method works. I
would research it more, but for some reason MSDN's web site isn't working
well right now. I expected that it would start its own message pump on
the thread on which you call ShowDialog(), but maybe it somehow simply
configures the message pump on the form's creating thread to do the work
(possibly calling Invoke() implicitly? I'm not sure).
Anyway, the bottom line is that there's something fishy about the code you
posted. I certainly wouldn't write the code that way, nor do I see any
reason to.
Quote:
The thing is that I
want to be able to open a few "second" forms, each one modifying the
database. Would using Invoke help?
I don't see why needing "a few 'second' forms" is cause for creating new
threads. You can create as many forms as you like. If you want more than
one to be active at once, then they need to be modeless, shown with the
Show() method rather than the ShowDialog() method. And if you want them
to all be active but the user to not be able to interact with the primary
form, then you'll need to disable the primary form yourself. But there's
no fundamental reason to create multiple threads, nor do I think it's a
safe approach.
You could try using Invoke(), but if you're using VS 2005 and are sure
that the cross-thread call MDA check is enabled, and you're not seeing the
MDA exception, then I don't see what using Invoke() would solve. If it
does fix the problem, then it means that you've somehow figured out a way
to make a GUI cross-thread call without the MDA noticing. :)
For sure, you should use Invoke() (or BeginInvoke()) any time you are
trying to call into methods on a Control instance from a thread other than
the thread on which that Control was created. But according to you,
that's not happening here.
Pete