示例#1
0
        // *************** Asynchronous Post *********************
        public static void RestPostAsync <TR, TI>(string url, TI data,
                                                  RestCallBack <TR> callback, ClientConfiguration configuration)
        {
            var post = new PostDelegate <TR, TI>(RestPost <TR, TI>);

            post.BeginInvoke(url, data, configuration,
                             ar =>
            {
                var result  = (AsyncResult)ar;
                var del     = (PostDelegate <TR, TI>)result.AsyncDelegate;
                var value   = default(TR);
                Exception e = null;

                try { value = del.EndInvoke(result); }
                catch (Exception ex) { e = ex; }

                callback?.Invoke(e, value);
            }, null);
        }
        // *************** Asynchronous Post *********************
        internal void RestPostAsync(string url, string data,
                                    RestCallBack <string> callback, ClientConfiguration configuration)
        {
            var post = new PostDelegate <string, string>(RestPost);

            post.BeginInvoke(url, data, configuration,
                             ar =>
            {
                var result  = (AsyncResult)ar;
                var del     = (PostDelegate <string, string>)result.AsyncDelegate;
                var value   = string.Empty;
                Exception e = null;

                try { value = del.EndInvoke(result); }
                catch (Exception ex) { e = ex; }

                if (callback != null)
                {
                    callback(e, value);
                }
            }, null);
        }