Reputation: 20916
private void manager_OnWebSiteVisited(object source, WebSiteVisitedEventArgs args)
{
if (InvokeRequired)
txtStatus.BeginInvoke(new WebSiteVisitedCallback(WebSiteVisited), new object[] { args });
else
txtStatus.Invoke(new WebSiteVisitedCallback(WebSiteVisited), new object[] { args });
}
InvokeEvent: Invoke or BeginInvoke cannot be called on a control until the window handle has been created.
i can use if (IsHandleCreated) but i do not know what to do if is not created. How to create it?
Upvotes: 0
Views: 6322
Reputation: 292425
Just access the Handle
property, it will create the handle if it's not already created. You can also call the CreateHandle
method explicitly.
if (!this.IsHandleCreated)
{
this.CreateHandle();
}
By the way, your usage of InvokeRequired/Invoke/BeginInvoke
is wrong: if InvokeRequired
is false, you shouldn't use Invoke
at all, you should call the method directly. I think what you want to do is this:
if (InvokeRequired)
txtStatus.Invoke(new WebSiteVisitedCallback(WebSiteVisited), new object[] { args });
else
WebSiteVisited(args);
Upvotes: 11