Sunday, March 25, 2012

How to: Close Windows form while doing CreateHandle()

The error Value Close() cannot be called while doing CreateHandle() usually happens when we try to close the form in the constructor or Load event.
For example,

the following code gives the error:

private void frmCustomer_Load(object sender, EventArgs e)
{
if (!Valid())
this.Close;
}

The Solution:

private void frmCustomer_Load(object sender, EventArgs e)
{
if (!Valid())
this.BeginInvoke(new MethodInvoker(Close));

2 comments:

  1. The best bonuses for December 2021 - JDH Hub
    At The 시흥 출장안마 Wizard 논산 출장샵 of Oz Casino, there are 2 bonuses for 제주 출장마사지 new players to play: · 안양 출장마사지 Deposit 영천 출장샵 £10 or more and receive €5 casino bonus: · Min deposit £10.

    ReplyDelete