Home All Groups Group Topic Archive Search About

Showing a form from within a thread

Author
6 Aug 2006 8:56 AM
Jerry Spence1
I have the following which generates MDI forms, but doesn't show them at
this stage:

For n As Integer = 1 To 10

fmViewer(n) = New frmViewer

fmViewer(n).Tag = n

fmViewer(n).MdiParent = Frm1

Next

From within a new thread I wish to show a form:

fmViewer(4).show

However, it doesn't show. The answer I am sure is because I am trying to
show it from within a thread. How can I achieve this?

-Jerry

Author
6 Aug 2006 4:02 PM
iwdu15
is fmViewer an array? or are you trying to do something else....please
explain a little bit more
--
-iwdu15
Author
7 Aug 2006 1:34 PM
Chris Dunaway
Jerry Spence1 wrote:
Show quoteHide quote
> I have the following which generates MDI forms, but doesn't show them at
> this stage:
>
> For n As Integer = 1 To 10
>
> fmViewer(n) = New frmViewer
>
> fmViewer(n).Tag = n
>
> fmViewer(n).MdiParent = Frm1
>
> Next
>
> From within a new thread I wish to show a form:
>
> fmViewer(4).show
>
> However, it doesn't show. The answer I am sure is because I am trying to
> show it from within a thread. How can I achieve this?

What is frmViewer?  Here you are using it as both the name of your
class and the name of the array variable.  Can you show us the
declaration for frmViewer?

Chris
Author
7 Aug 2006 8:52 PM
Jerry Spence1
Hi Chris

fmViwer is the name of my form, fmViewer() is an array. I can see the
difference is rather small!

-Jerry


Show quoteHide quote
"Chris Dunaway" <dunaw***@gmail.com> wrote in message
news:1154957680.048491.134180@m79g2000cwm.googlegroups.com...
> Jerry Spence1 wrote:
>> I have the following which generates MDI forms, but doesn't show them at
>> this stage:
>>
>> For n As Integer = 1 To 10
>>
>> fmViewer(n) = New frmViewer
>>
>> fmViewer(n).Tag = n
>>
>> fmViewer(n).MdiParent = Frm1
>>
>> Next
>>
>> From within a new thread I wish to show a form:
>>
>> fmViewer(4).show
>>
>> However, it doesn't show. The answer I am sure is because I am trying to
>> show it from within a thread. How can I achieve this?
>
> What is frmViewer?  Here you are using it as both the name of your
> class and the name of the array variable.  Can you show us the
> declaration for frmViewer?
>
> Chris
>
Author
7 Aug 2006 3:29 PM
Brian Gideon
Jerry,

All Form access must be done from the main UI thread.  That includes
creating, manipulating, and showing the Form.  You'll need a reference
to an existing Form or Control that your worker thread will use to
marshal the execution of a delegate onto the UI thread by calling
Invoke or BeginInvoke.  That delegate should contain the code to create
and show the new Form.  Invoke and BeginInvoke are among the very few
members of a Form or Control that are actually thread-safe.

Brian

Jerry Spence1 wrote:
Show quoteHide quote
> I have the following which generates MDI forms, but doesn't show them at
> this stage:
>
> For n As Integer = 1 To 10
>
> fmViewer(n) = New frmViewer
>
> fmViewer(n).Tag = n
>
> fmViewer(n).MdiParent = Frm1
>
> Next
>
> From within a new thread I wish to show a form:
>
> fmViewer(4).show
>
> However, it doesn't show. The answer I am sure is because I am trying to
> show it from within a thread. How can I achieve this?
>
> -Jerry
Author
7 Aug 2006 8:53 PM
Jerry Spence1
Show quote Hide quote
"Brian Gideon" <briangid***@yahoo.com> wrote in message
news:1154964586.043590.211090@i42g2000cwa.googlegroups.com...
> Jerry,
>
> All Form access must be done from the main UI thread.  That includes
> creating, manipulating, and showing the Form.  You'll need a reference
> to an existing Form or Control that your worker thread will use to
> marshal the execution of a delegate onto the UI thread by calling
> Invoke or BeginInvoke.  That delegate should contain the code to create
> and show the new Form.  Invoke and BeginInvoke are among the very few
> members of a Form or Control that are actually thread-safe.
>
> Brian
>
> Jerry Spence1 wrote:
>> I have the following which generates MDI forms, but doesn't show them at
>> this stage:
>>
>> For n As Integer = 1 To 10
>>
>> fmViewer(n) = New frmViewer
>>
>> fmViewer(n).Tag = n
>>
>> fmViewer(n).MdiParent = Frm1
>>
>> Next
>>
>> From within a new thread I wish to show a form:
>>
>> fmViewer(4).show
>>
>> However, it doesn't show. The answer I am sure is because I am trying to
>> show it from within a thread. How can I achieve this?
>>
>> -Jerry
>

Thanks Brian. I'll have a look at  Invoke and BeginInvoke.

-Jerry