Callback C # And JS synchronous and asynchronous implementation,

Source: Internet
Author: User

Callback C # And JS synchronous and asynchronous implementation,

The code is very simple and I will not explain it much. If you have any questions or suggestions, please leave a message and reply immediately.

C # code first

Class Program {static void Main (string [] args) {MyCallback mc = new MyCallback (); mc. callback (new Action (success), new Action (failed); mc. callback (new Action () => {Console. writeLine ("No parameter anonymous success") ;}, new Action () =>{ Console. writeLine ("No parameter anonymous failed") ;}); mc. callback (new Action <object> (success), new Action <object> (failed); Console. readKey (); // from http://www.cnblogs.com/ahjesus Respect the author's hard work, and repost the source. Thank you!} Static void success () {Console. writeLine ("success");} static void failed () {Console. writeLine ("No parameter failed");} static void success (object str) {Console. writeLine (string) str);} static void failed (object str) {Console. writeLine (int) str) ;}} class MyCallback {public void Callback (Action success, Action failed) {success (); failed (); // from http://www.cnblogs.com/ahjesus Respect the author's hard work, and repost the source. Thank you!} Public void Callback (Action <object> success, Action <object> failed) {success ("123"); failed (456 );}}

JS Code

<Script type = "text/javascript"> var mc = new MyCallback (); mc. callback (success, failed); console. logs (222); function success (str) {console. log (str);} function failed (num) {console. log (num);} mc. callback (function (str) {console. log (str) ;}, function (num) {console. log (num); // from http://www.cnblogs.com/ahjesus Respect the author's hard work, and repost the source. Thank you! }) Console. logs (333); function MyCallback () {this. callback = function (success, failed) {// No parameter. If you have any parameter, choose not to pass the parameter successDelegate = success; // from http://www.cnblogs.com/ahjesus Respect the author's hard work, and repost the source. Thank you! FailedDelegate = failed; setTimeout ('successdelegate ("111") ', 1000); // asynchronous setTimeout ('faileddelegate ("444")', 4000 ); // asynchronous // success ("123"); // synchronous // failed (456); // synchronous }</script>

 

 

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.