C # asynchronous callback instance for multi-threaded parameter passing and return values

Source: Internet
Author: User

[Csharp]

Delegate bool MyDelete (TreeNodeCollection node );
Bool prrelust = false;
Bool xz.pdf = false;
Bool prrelust = false;
Bool xz.pdf = false;
Public bool PrintTreeViewNode (TreeNodeCollection node)
{
 
 
Foreach (TreeNode n in node)
{
 
 
If (n. Checked & (Convert. ToInt32 (n. Tag) = 30 ))
{
Xztasks = true;
String fanode = n. Parent. Parent. Text;
String time = cbTimeDelay. Text. Trim (). Substring (0, cbTimeDelay. Text. Trim (). Length-1); // latency
Int jihao = Convert. toInt32 (fanode. substring (fanode. indexOf ("(") + 1, fanode. indexOf (")")-fanode. indexOf ("(")-1); // host number
Int menhao; // Door Number
GCR. DoorSedBll bl = new GCR. DoorSedBll ();
 
 
If (n. Parent. Text! = "Host ")
{
Menhao = Convert. ToInt32 (n. Parent. Tag) * 8 + 4 + n. Index;
}
Else
{
Menhao = n. Index; // Door Number
}
Prrelust = bl. OpenDoorTimedelaySet (jihao, menhao, Convert. ToInt32 (time ));
 
 
 
 
 
 
If (! Prrelust)
{
Label3.Text = "";
Break;
}
 
 
}
PrintTreeViewNode (n. Nodes );
}
 
 
 
 
Return prrelust;
 
 
 
 
 
 
}
# Endregion
 
 
Private void btOpenDoorTimeSet_Click (object sender, EventArgs e)
{
Label3.Text = "loading delayed. Please wait .......";
MyDelete Dele = new MyDelete (PrintTreeViewNode );
Dele. BeginInvoke (this. tvDevc. Nodes, new AsyncCallback (AfterMyMothod), null );
 
 
}
# Endregion
 
 
# Region callback function for asynchronous parameter passing
Public void AfterMyMothod (IAsyncResult result)
{
 
 
AsyncResult async = (AsyncResult) result;
MyDelete DelegateInstance = (MyDelete) async. AsyncDelegate;
Bool rt = DelegateInstance. EndInvoke (result );
If (xztasks)
{
 
 
If (rt)
{
MessageBox. Show ("delayed loading successful! "," Prompt ", MessageBoxButtons. OK, MessageBoxIcon. Information );
 
 
}
Else
{
MessageBox. Show ("delayed loading failed !, Please reload! "," Error prompt ", MessageBoxButtons. OK, MessageBoxIcon. Error );
 
 
}
}
Else
{
 
 
MessageBox. Show ("select the control host number", "prompt", MessageBoxButtons. OK, MessageBoxIcon. Error );
}
Label3.Text = "";
}
# Endregion


Delegate bool MyDelete (TreeNodeCollection node );
Bool prrelust = false;
Bool xz.pdf = false;
Bool prrelust = false;
Bool xz.pdf = false;
Public bool PrintTreeViewNode (TreeNodeCollection node)
{


Foreach (TreeNode n in node)
{


If (n. Checked & (Convert. ToInt32 (n. Tag) = 30 ))
{
Xztasks = true;
String fanode = n. Parent. Parent. Text;
String time = cbTimeDelay. Text. Trim (). Substring (0, cbTimeDelay. Text. Trim (). Length-1); // latency
Int jihao = Convert. toInt32 (fanode. substring (fanode. indexOf ("(") + 1, fanode. indexOf (")")-fanode. indexOf ("(")-1); // host number
Int menhao; // Door Number
GCR. DoorSedBll bl = new GCR. DoorSedBll ();


If (n. Parent. Text! = "Host ")
{
Menhao = Convert. ToInt32 (n. Parent. Tag) * 8 + 4 + n. Index;
}
Else
{
Menhao = n. Index; // Door Number
}
Prrelust = bl. OpenDoorTimedelaySet (jihao, menhao, Convert. ToInt32 (time ));

 

 


If (! Prrelust)
{
Label3.Text = "";
Break;
}


}
PrintTreeViewNode (n. Nodes );
}

 


Return prrelust;

 

 


}
# Endregion


Private void btOpenDoorTimeSet_Click (object sender, EventArgs e)
{
Label3.Text = "loading delayed. Please wait .......";
MyDelete Dele = new MyDelete (PrintTreeViewNode );
Dele. BeginInvoke (this. tvDevc. Nodes, new AsyncCallback (AfterMyMothod), null );


}
# Endregion


# Region callback function for asynchronous parameter passing
Public void AfterMyMothod (IAsyncResult result)
{


AsyncResult async = (AsyncResult) result;
MyDelete DelegateInstance = (MyDelete) async. AsyncDelegate;
Bool rt = DelegateInstance. EndInvoke (result );
If (xztasks)
{


If (rt)
{
MessageBox. Show ("delayed loading successful! "," Prompt ", MessageBoxButtons. OK, MessageBoxIcon. Information );


}
Else
{
MessageBox. Show ("delayed loading failed !, Please reload! "," Error prompt ", MessageBoxButtons. OK, MessageBoxIcon. Error );


}
}
Else
{


MessageBox. Show ("select the control host number", "prompt", MessageBoxButtons. OK, MessageBoxIcon. Error );
}
Label3.Text = "";
}
# Endregion

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.