zoukankan      html  css  js  c++  java
  • C# 异步操作

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; namespace ConsoleApplication22 { /// /// 异步操作 /// ///  ///  /// delegate int MainRun(int data,int sleep); class Program { static void Main(string[] args) { MainRun mainRun = TakeAWhile; IAsyncResult ar = mainRun.BeginInvoke(1, 300, null, null); while (!ar.IsCompleted) { Console.WriteLine("."); Thread.Sleep(100); } int result = mainRun.EndInvoke(ar); Console.WriteLine("Result :{0}",result); } static int TakeAWhile(int data, int sleep) { Console.WriteLine("TakesAWhile stated"); Thread.Sleep(sleep); Console.WriteLine("TakesAWhile completed"); return ++data; } } }

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">

        <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>

        <title></title>

        <link href="Styles/Site.css" rel="stylesheet" type="text/css" />

        <script type="text/javascript">

            $(function () {

                //¦¨¨??º?¡Â

                $('#ajax01').ajaxStart(function () { $(this).show() }).ajaxSuccess(function () { $(this).hide() }).ajaxError(function () { $(this).hide(); alert(msg) });

                $('#btnGet').click(function () {

                    var number = $('#Text1').val();

     

                    $.get('Handler.ashx?number=' + number, function (result) {

                        alert(result);

                    });

     

                });

                $('#btnPost').click(function () {

                    var number = $('#Text1').val();

                    $.post('Handler.ashx', { 'number': number }, function (result) {

                        alert(result);

                    });

     

                });

     

            });

       

        </script>

    </head>

    <body>

        <form id="form1" runat="server">

        <div id="ajax01">

            <img src="image/loading.gif" />Loading...<br>

            ?º?¨?°??ºyÁ?:<input id="Text1" type="text" /><br />

            <input id="btnGet" type="button" value="get Mode" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            <input id="btnPost" type="button" value="post  Mode" /></div>

        </form>

    </body>

    </html>

     

    ////Hander.ashx

     

    <%@ WebHandler Language="C#" Class="Handler" %>

     

    using System;

    using System.Web;

     

    public class Handler : IHttpHandler {

       

        public void ProcessRequest (HttpContext context) {

           

            context.Response.ContentType = "text/plain";

     

     

            int number = 0;

            int.TryParse(context.Request.Params["number"], out number);

            context.Response.StatusCode = 200;

            context.Response.Cache.SetCacheability(HttpCacheability.NoCache);

           

           

            context.Response.Write(string.Format("{0}º?{1}",number,Math.Pow(3,number)));

            context.Response.End();

        }

     

        public bool IsReusable {

            get {

                return false;

            }

        }

     

    }

     

     

  • 相关阅读:
    字体文件以base64编码的方式引入内嵌到样式文件中
    css content 如何自定义生成图标?
    很好的个人博客网址
    较好的第三方框架-网址
    html Javascript MD5
    html svg 编辑器
    ajax笔试面试题
    工作备忘录
    移动端页面兼容性问题解决方案整理(三)
    移动端页面兼容性问题解决方案整理(二)
  • 原文地址:https://www.cnblogs.com/fat_li/p/1923295.html
Copyright © 2011-2022 走看看