Somebody please HELP!
This .NET problem is killing me!
NOTE: JAVA HAS NO SUCH PROBLEM!!!!!
Why tie a window to a thread!?!?!?
Why create a handle ONLY when it is visible?
> Why tie a window to a thread!?!?!?
Its a Win32 limitation, System.Windows.Forms is based on (thin wrappers of)
Win32 Windows.
> Why create a handle ONLY when it is visible?
You can use Control.IsHandleCreated to see if the handle is created yet or
not. You should be able to use Control.CreateControl to create the handle,
if its not yet created.
My concern would be using CreateControl from a worker thread, as that may
cause the BeginInvoke to need to be handled on the worker thread and not the
main thread. I have not actually used forms on multiple threads, so I'm not
sure what will happen... I would probably simply call CreateControl on the
main thread, so there's no question.
Hope this helps
Jay
"Altramagnus" <altra...@hotmail.com> wrote in message
news:294efb48.04062...@posting.google.com...
"Jay B. Harlow [MVP - Outlook]" <Jay_Har...@msn.com> wrote in message
news:uduI4tYX...@TK2MSFTNGP09.phx.gbl...
Yes I would love to.
But it is not up to me to decide.
My customer insist on C#
>
> > Why tie a window to a thread!?!?!?
> Its a Win32 limitation, System.Windows.Forms is based on (thin wrappers
of)
> Win32 Windows.
>
> > Why create a handle ONLY when it is visible?
> You can use Control.IsHandleCreated to see if the handle is created yet or
> not. You should be able to use Control.CreateControl to create the handle,
> if its not yet created.
I tried this:
Form f = new Form();
Console.WriteLine( f.IsHandleCreated );
f.CreateControl();
Console.WriteLine( f.IsHandleCreated );
f.Show();
Console.WriteLine( f.IsHandleCreated );
Output is:
false
false
true
so handle is only created when it is first shown.
In this case 'Control.InvokeRequired' will return 'False' and you can
access the controls directly. Nevertheless, you will have to make sure
that the state of the UI doesn't change (the form is not shown), because
this may require to use invoke.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Thanks for the info.
I did not realize that Control.InvokeRequired will return False when handle
is not created yet.
This solves the updating part. But I am required to show the form after
updating.
When the form is initially hidden, the handle is not created, I could not
call invoke from a worker thread
to show it, because without a handle, invoke cannot be called.
I could not call .Show() directly from the work thread either, because that
will tie the window to my worker thread.
Then how do I change the visibility with my worker thread ( intially hidden
when handle is not created )?
why can't we force the handle to be created when the form is invisible?
Isn't that what the CreateControl() should do?
Thanks.
An alternative solution to calling Invoke would be to raise an event and
have your forms do what they have to do in the event handler. The event
machinery will cope with thread marshalling issues.
HTH
"Altramagnus" <altra...@hotmail.com> wrote in message
news:294efb48.04062...@posting.google.com...
Now I'm curious on when one would actually use Control.CreateControl.
I'll see what I can find out.
Hope this helps
Jay
"Altramagnus" <altra...@hotmail.com> wrote in message
news:40e0fa7c$1...@news.starhub.net.sg...
If you call Form.Handle, the handle will be created for you.
Debug.WriteLine(form.IsHandleCreated, "IsHandleCreated")
Debug.WriteLine(form.Handle.ToInt32(), "Handle")
form.CreateControl()
Debug.WriteLine(form.IsHandleCreated, "IsHandleCreated")
Debug.WriteLine(form.Handle.ToInt32(), "Handle")
If I take out the calls to form.Handle, I get the effect you describe, if I
leave them in the handle is created. I am checking on when you would
actually use CreateControl, as it appears (as you stated) not to do anything
for a Form.
FWIW: I used "form.Handle.ToInt32()" to avoid the debugger from displaying
the value of the Handle itself, invalidating my test...
Hope this helps
Jay
"Altramagnus" <altra...@hotmail.com> wrote in message
news:40e0fa7c$1...@news.starhub.net.sg...
Thanks.
"François J. Miton" <fmi...@online.microsoft.com> wrote in message
news:ukb9WldX...@TK2MSFTNGP09.phx.gbl...