C # Ajax/async (msxml2.xmlhttp)

Source: Internet
Author: User

You can tell from the following code that it is a ajax,objajax.onreadystatechange of asynchronous memory =

New onReadyStateChange (Objajax, New EventHandler (onreadystatechange))

with JScript code ajax.onreadystatechange = function () {}; the essence is the same, but

The method I use is its internal form.

    public class program    {public        static void Main (string[] args)        {            Dynamic Objajax = Activator.CreateInstance (Type.gettypefromprogid ("msxml2.xmlhttp"));            Objajax.open ("GET", "http://blog.csdn.net/u012395622", true);            Objajax.onreadystatechange = new onReadyStateChange (Objajax, New EventHandler (onreadystatechange));            Objajax.send (null);            Console.readkey (FALSE);        }        public static void onReadyStateChange (object sender, EventArgs e)        {            dynamic objajax = sender;            if (objajax.readystate = = 4 | | objajax.status = =)                Console.WriteLine ("success\r\n" + objajax.responsetext);            Else                Console.WriteLine ("Fail");        }    }

There are a lot of people in C # using AJAX there's no way to add callback functions

But they were smart enough to take another approach, and Ajax.waitforresponse (Timeoutinseconds)

Wait for asynchronous send to complete, with optional timeout.

Generally provided infinite = 1 However, doing so will block the thread, but will not block the UI remember a few years ago someone

Did this experiment, regardless of when it is used winhttp/com object, speaking of WinHTTP I have a post

the sub is encapsulated The Winhttp/com sample code is a simple short-click continuation Download.

You can see that although there will be some people do not sharpen but I do not care about language rejection language is not a good programmer.

http://bbs.125.la/forum.php?mod=viewthread&tid=13771462 But since I'm talking about Asynchrony,

Way so certainly will be asynchronous, otherwise not hit my own face is not, hehe always feel so happy?

Using system;using system.reflection;using system.globalization;

    public class Onreadystatechange:ireflect {private volatile object m_sender;             private volatile ireflect m_reflect;        private volatile EventHandler m_event;            Public onReadyStateChange (object sender, EventHandler EventHandler) {this.m_sender = sender;            This.m_event = EventHandler;        This.m_reflect = typeof (onReadyStateChange); } Type Ireflect.underlyingsystemtype {get {return this.m_reflect.            Underlyingsystemtype; }} FieldInfo Ireflect.getfield (string name, BindingFlags bindingattr) {return this.m_ref Lect.        GetField (name, bindingattr); } fieldinfo[] Ireflect.getfields (BindingFlags bindingattr) {return this.m_reflect.        GetFields (bindingattr); } memberinfo[] Ireflect.getmember (string name, BindingFlags bindingattr) {return this.m_reflect. GetMember (Name, BINDINGATTR); } memberinfo[] Ireflect.getmembers (BindingFlags bindingattr) {return this.m_reflect.        GetMembers (bindingattr); } MethodInfo Ireflect.getmethod (string name, BindingFlags bindingattr) {return this.m_reflect.        GetMethod (name, bindingattr); } MethodInfo Ireflect.getmethod (string name, BindingFlags bindingattr, Binder binder, type[] types, Parametermodifi Er[] modifiers) {return this.m_reflect.        GetMethod (name, bindingattr, binder, types, modifiers); } methodinfo[] Ireflect.getmethods (BindingFlags bindingattr) {return this.m_reflect.        GetMethods (bindingattr); } propertyinfo[] Ireflect.getproperties (BindingFlags bindingattr) {return this.m_reflect.        GetProperties (bindingattr); } PropertyInfo Ireflect.getproperty (string name, BindingFlags bindingattr) {return This.m_reflec T.getproperty (name, biNDINGATTR); } PropertyInfo Ireflect.getproperty (string name, BindingFlags bindingattr, Binder binder, Type returntype, type[] t Ypes, parametermodifier[] modifiers) {return this.m_reflect.        GetProperty (name, bindingattr); } object Ireflect.invokemember (string name, BindingFlags invokeattr, Binder binder, Object target, object[] args, P Arametermodifier[] modifiers, CultureInfo culture, string[] namedparameters) {if (name = = "[Dispid=0]" &            amp;& this.m_event! = null) this.m_event (This.m_sender, eventargs.empty); Return This.m_reflect.        InvokeMember (name, invokeattr, binder, Target, args, modifiers, culture, namedparameters); }    }

C # Ajax/async (msxml2.xmlhttp)

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.