Pls help: a problem about IsHandleCreated property

A

AA

In my application, I create a form A and I pass the form A reference to another form B.
When I try to check the IsHandleCreated property of the form A, it always return false. So, I cannot call the begininvoke of the form A as the IsHandleCreated always return false.
Actually, the form A already show in the screen. WHy the IsHandleCreated is still false? When I call a function in formB, I want formA' s thread to call a function rather than using FormB's thread to call the function in form A.

Eg: It is some part of code in FormB.
if (frmA.IsHandleCreated)
{
frmA.BeginInvoke (new RefreshFunction (frmA.RefreshStrategy), new object[] {strategyid});
}

How to fix it this ptoblem?
Thanks

Anthony
 
A

AA

When I ceate the formA, the code is below:
If there is any wrong for the creation of formA to trigger this problem, please let me know.

FormA a = new FormA();
a.Owner = this;

FormB b = new FormB();
b.Owner = this;
b.frmA = a;


Thanks
"AA" <[email protected]> ¼¶¼g©ó¶l¥ó·s»D:[email protected]....
In my application, I create a form A and I pass the form A reference to another form B.
When I try to check the IsHandleCreated property of the form A, it always return false. So, I cannot call the begininvoke of the form A as the IsHandleCreated always return false.
Actually, the form A already show in the screen. WHy the IsHandleCreated is still false? When I call a function in formB, I want formA' s thread to call a function rather than using FormB's thread to call the function in form A.

Eg: It is some part of code in FormB.
if (frmA.IsHandleCreated)
{
frmA.BeginInvoke (new RefreshFunction (frmA.RefreshStrategy), new object[] {strategyid});
}

How to fix it this ptoblem?
Thanks

Anthony
 
T

Tom Porterfield

Why are you calling IsHandleCreated? A handle isn't necessarily created if it isn't needed. If you want to force a handle to be created simply access frmA.Handle. But again, what is the intent of your code by checking that before executing your delegate?
--
Tom Porterfield
In my application, I create a form A and I pass the form A reference to another form B.
When I try to check the IsHandleCreated property of the form A, it always return false. So, I cannot call the begininvoke of the form A as the IsHandleCreated always return false.
Actually, the form A already show in the screen. WHy the IsHandleCreated is still false? When I call a function in formB, I want formA' s thread to call a function rather than using FormB's thread to call the function in form A.

Eg: It is some part of code in FormB.
if (frmA.IsHandleCreated)
{
frmA.BeginInvoke (new RefreshFunction (frmA.RefreshStrategy), new object[] {strategyid});
}

How to fix it this ptoblem?
Thanks

Anthony
 
W

Willy Denoyette [MVP]

When I ceate the formA, the code is below:
If there is any wrong for the creation of formA to trigger this problem, please let me know.

FormA a = new FormA();
a.Owner = this;

FormB b = new FormB();
b.Owner = this;
b.frmA = a;


Thanks
"AA" <[email protected]> ¼¶¼g©ó¶l¥ó·s»D:[email protected]....
In my application, I create a form A and I pass the form A reference to another form B.
When I try to check the IsHandleCreated property of the form A, it always return false. So, I cannot call the begininvoke of the form A as the IsHandleCreated always return false.
Actually, the form A already show in the screen. WHy the IsHandleCreated is still false? When I call a function in formB, I want formA' s thread to call a function rather than using FormB's thread to call the function in form A.

Eg: It is some part of code in FormB.
if (frmA.IsHandleCreated)
{
frmA.BeginInvoke (new RefreshFunction (frmA.RefreshStrategy), new object[] {strategyid});
}

How to fix it this ptoblem?
Thanks

Anthony




Adding to what Tom said, you don't need to call BeginInvoke, both of your forms are created on the same thread, so there is no cross-thread marshaling needed.

Willy.
 
G

Guest

Actually,. the form B is create by another thread. Both FormA and FormB are not created by the same thread. But in my coding example, it may make you confuse.
When I call the frmA.BeginInvoke (new RefreshFunction (frmA.RefreshStrategy) , new object[] {strategyid}) in form B(create by another thread), it throw the exeption "Cannot call Invoke or InvokeAsync on a control until the window handle has been created."
So, when I check the IsHandleCreated od FOrmA, it shows false.

Why are you calling IsHandleCreated? A handle isn't necessarily created if it isn't needed. If you want to force a handle to be created simply access frmA.Handle. But again, what is the intent of your code by checking that before executing your delegate?
--
Tom Porterfield
In my application, I create a form A and I pass the form A reference to another form B.
When I try to check the IsHandleCreated property of the form A, it always return false. So, I cannot call the begininvoke of the form A as the IsHandleCreated always return false.
Actually, the form A already show in the screen. WHy the IsHandleCreated is still false? When I call a function in formB, I want formA' s thread to call a function rather than using FormB's thread to call the function in form A.

Eg: It is some part of code in FormB.
if (frmA.IsHandleCreated)
{
frmA.BeginInvoke (new RefreshFunction (frmA.RefreshStrategy), new object[] {strategyid});
}

How to fix it this ptoblem?
Thanks

Anthony
 
T

Tom Porterfield

<abc.com> wrote in message Actually,. the form B is create by another thread. Both FormA and FormB are not created by the same thread. But in my coding example, it may make you confuse.
When I call the frmA.BeginInvoke (new RefreshFunction (frmA.RefreshStrategy) , new object[] {strategyid}) in form B(create by another thread), it throw the exeption "Cannot call Invoke or InvokeAsync on a control until the window handle has been created."
So, when I check the IsHandleCreated od FOrmA, it shows false.
So as I said, if you ask for the handle (frmA.Handle) that will force it to be created if it isn't.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top