I have a form first created my the main thread.
I have another thread monitoring the IO.
Upon receiving certain message, I want to show/unhide the form.

When the form is first created ( handle is not created until it is first
shown ).
How do my IO thread invoke the form to show? ( in order to invoke the form,
the form handle must be created )

Thanks.

Re: How to invoke a form to show? by Armin

Armin
Thu May 12 09:14:24 CDT 2005

"Altramagnus" <altramagnus@hotmail.com> schrieb
>I have a form first created my the main thread.
> I have another thread monitoring the IO.
> Upon receiving certain message, I want to show/unhide the form.
>
> When the form is first created ( handle is not created until it is
> first shown ).
> How do my IO thread invoke the form to show? ( in order to invoke the
> form, the form handle must be created )
>
> Thanks.

2 suggestions: You could call CreateHandle in the main thread after the form
has been created. Or, use an empty dummy form created in the main thread
used by (Begin)Invoke in the 2nd thread. The target procedure in the main
thread then shows the actual form.

Armin


Re: How to invoke a form to show? by Altramagnus

Altramagnus
Fri May 13 02:40:29 CDT 2005

Thanks

The first method would not work because,
even you explictly call CreateHandle, the handle would still not be created
until the form is first visible.
In other words, if the form is not visible, createHandle does nothing.

The second method works if i have a existing form that is already shown.
It will still be a problem if I have no existing form.

Thanks.



"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:%23cdXxAwVFHA.1152@tk2msftngp13.phx.gbl...
> "Altramagnus" <altramagnus@hotmail.com> schrieb
>>I have a form first created my the main thread.
>> I have another thread monitoring the IO.
>> Upon receiving certain message, I want to show/unhide the form.
>>
>> When the form is first created ( handle is not created until it is
>> first shown ).
>> How do my IO thread invoke the form to show? ( in order to invoke the
>> form, the form handle must be created )
>>
>> Thanks.
>
> 2 suggestions: You could call CreateHandle in the main thread after the
> form has been created. Or, use an empty dummy form created in the main
> thread used by (Begin)Invoke in the 2nd thread. The target procedure in
> the main thread then shows the actual form.
>
> Armin



Re: How to invoke a form to show? by Armin

Armin
Fri May 13 03:25:52 CDT 2005

"Altramagnus" <altramagnus@hotmail.com> schrieb
> "Armin Zingler" <az.nospam@freenet.de> wrote in message
> news:%23cdXxAwVFHA.1152@tk2msftngp13.phx.gbl...
>> "Altramagnus" <altramagnus@hotmail.com> schrieb
>>>I have a form first created my the main thread.
>>> I have another thread monitoring the IO.
>>> Upon receiving certain message, I want to show/unhide the form.
>>>
>>> When the form is first created ( handle is not created until it
>>> is first shown ).
>>> How do my IO thread invoke the form to show? ( in order to invoke
>>> the form, the form handle must be created )
>>
>> 2 suggestions: You could call CreateHandle in the main thread after
>> the form has been created. Or, use an empty dummy form created in
>> the main thread used by (Begin)Invoke in the 2nd thread. The target
>> procedure in the main thread then shows the actual form.
>>
>
> The first method would not work because,
> even you explictly call CreateHandle, the handle would still not be
> created until the form is first visible.
> In other words, if the form is not visible, createHandle does
> nothing.

Sure? I tried it and it worked. In a new project, add a button and this code
(sorry, VB.NET, but you'll see the point):

Shared f As Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

f = New Form1
f.CreateHandle()
Dim t As New Threading.Thread(AddressOf a)
t.Start()
End Sub
Private Delegate Sub d()
Private Shared Sub a()
f.BeginInvoke(New d(AddressOf b))
End Sub
Private Shared Sub b()

End Sub

Exception without createhandle, no exception with createhandle.


> The second method works if i have a existing form that is already
> shown. It will still be a problem if I have no existing form.

Yes, that's why you could add one, but you don't have to show it.


Armin


Re: How to invoke a form to show? by Altramagnus

Altramagnus
Fri May 13 05:12:52 CDT 2005

OK thanks.

I think CreateHandle works.
Sorry it was my mistake.



"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:u$WsFV5VFHA.1796@TK2MSFTNGP15.phx.gbl...
> "Altramagnus" <altramagnus@hotmail.com> schrieb
>> "Armin Zingler" <az.nospam@freenet.de> wrote in message
>> news:%23cdXxAwVFHA.1152@tk2msftngp13.phx.gbl...
>>> "Altramagnus" <altramagnus@hotmail.com> schrieb
>>>>I have a form first created my the main thread.
>>>> I have another thread monitoring the IO.
>>>> Upon receiving certain message, I want to show/unhide the form.
>>>>
>>>> When the form is first created ( handle is not created until it
>>>> is first shown ).
>>>> How do my IO thread invoke the form to show? ( in order to invoke
>>>> the form, the form handle must be created )
>>>
>>> 2 suggestions: You could call CreateHandle in the main thread after
>>> the form has been created. Or, use an empty dummy form created in
>>> the main thread used by (Begin)Invoke in the 2nd thread. The target
>>> procedure in the main thread then shows the actual form.
>>>
>>
>> The first method would not work because,
>> even you explictly call CreateHandle, the handle would still not be
>> created until the form is first visible.
>> In other words, if the form is not visible, createHandle does
>> nothing.
>
> Sure? I tried it and it worked. In a new project, add a button and this
> code
> (sorry, VB.NET, but you'll see the point):
>
> Shared f As Form1
> Private Sub Button1_Click(ByVal sender As System.Object, _
> ByVal e As System.EventArgs) Handles Button1.Click
>
> f = New Form1
> f.CreateHandle()
> Dim t As New Threading.Thread(AddressOf a)
> t.Start()
> End Sub
> Private Delegate Sub d()
> Private Shared Sub a()
> f.BeginInvoke(New d(AddressOf b))
> End Sub
> Private Shared Sub b()
>
> End Sub
>
> Exception without createhandle, no exception with createhandle.
>
>
>> The second method works if i have a existing form that is already
>> shown. It will still be a problem if I have no existing form.
>
> Yes, that's why you could add one, but you don't have to show it.
>
>
> Armin
>