Functional Function Test Highlights (*)C # Zone (a)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
. NET prohibits access to controls across threads in principle, because this can cause errors, and one way is to prevent the compiler from checking cross-thread access, Control.checkforillegalcrossthreadcalls = false; But it's not a mistake to guarantee C # cross-thread access control run-time errors.
You can use MethodInvoker to solve:
Original code:
private void btnok_click (Object sender , eventargs e)
{
tslInfo.Text = "Please wait ...";
Thread td = New thread (New threadstart (run));
td. Start ();
}
/// <summary>
/// Threading Methods
/// </summary>
private void run ()
{
this.tslInfo.Text = "Ready";
}
After modification:
private void btnok_click (Object sender, eventargs e)
{
tslInfo.Text = "Please wait ...";
Thread td = New thread (New threadstart (ThreadRun));
td. Start ();
}
/// <summary>
/// Original Threading Method
/// </summary>
private void run ()
{
this.tslInfo.Text = "Ready";
}
<summary>
Threading Methods
</summary>
private void ThreadRun ()
{
MethodInvoker in = new MethodInvoker (run);
This. BeginInvoke (in);
}
C # uses MethodInvoker to resolve cross-thread access controls