Home
Links
Home Page
HTML_AJAX In operation
The guidebook on an exchange of links
Bases of creation of server elements of management. Events
Postback and Query String - to combine incompatible
Kategorial`noe ordering of results of search
We change URL'? hurriedly
XML+MSSQL+ASP.NET. A part 1.
As work Web services ASP.NET
New in ASP.NET 2. Structures of users
Transformation of a target stream of the XML-given at a conclusion in a browser means ASP.NET and XS
Expectation of performance of long process in ASP.NET
Difference between HttpModule and HttpHandler
New in asp.net 2 - subjects and skiny.
Review GridView
What is GridView
Role of a content in promotion of a site
Review DetailsView
Job with databases
AutoPostBack Binding to the data. Collections. Check of correctness of the entered data

Expectation of performance of long process in ASP.NET

We admit{allow}, we have page Default.aspx on which the user enters a name of the client and number{room} of the waybill then there is a check of this number{room}. As check can borrow{occupy} long time it is necessary to provide the user with the information on a course of performance of process (goes or has already passed). The simplest way is resulted below.


Default



using System;

using System. Data;

using System. Configuration;

using System. Collections;

using System. Web;

using System. Web. Security;

using System. Web. UI;

using System. Web. UI.WebControls;

using System. Web. UI.WebControls. WebParts;

using System. Web. UI.HtmlControls;

using System. Threading;


public partial class _Default: System. Web. UI.Page

{


    protected Guid _id;


    protected void Page_Load (object sender, EventArgs e)

    {

        if (Page. IsPostBack)

        {

            _id = Guid. NewGuid ();


            ThreadStart ts = new ThreadStart (Check);

            Thread th = new Thread (ts);

            th. Start ();


            Response. Redirect (" Invoice.aspx? ID = " + _id. ToString ());

}

}


    protected void Check ()

    {

        string res = InvoiceProcessor. CheckInvoice (txtName. Text, txtNumber. Text);

        CheckedInvoices. Add (_id, res);

}


}


Essence in that the unique identifier is created. On which the result will be received from the khehsh-table of results. An example of a class of table CheckedInvoices and a class - zaglushki which in the normal application carries out check InvoiceProcessor, are resulted below.


CheckedInvoices



using System;

using System. Collections;


public static class CheckedInvoices

{

    private static Hashtable _invoices = new Hashtable ();


    public static string GetResult (Guid id)

    {

        if (_invoices. Contains (id))

        {

            return Convert. ToString (_invoices [id]);

}

        else

        {

            return " ";

}

}


    public static void Add (Guid id, string value)

    {

        _invoices [id] = value;

}


    public static void Remove (Guid id)

    {

        _invoices. Remove (id);

}

}


InvoiceProcessor



using System;

using System. Threading;


public static class InvoiceProcessor

{

    public static string CheckInvoice (string customerName, string invoiceID)

    {

        Thread. Sleep (10000);

        if (invoiceID == "qwerty")

        {

            return " the Current status: it is transferred{handed} to service dostavkinOzhidaemoe time of delivery: the devil only knows ";

}

        else if (invoiceID == "asdfgh")

        {

            return " the Current status: dostavlenonOzhidaemoe time of delivery: so already ";

}

        else

        {

            return " there Is no information under the given waybill ";

}

}

}


The page on which readdressing is carried out, should check readiness of result only.


Invoice



using System;

using System. Data;

using System. Configuration;

using System. Collections;

using System. Web;

using System. Web. Security;

using System. Web. UI;

using System. Web. UI.WebControls;

using System. Web. UI.WebControls. WebParts;

using System. Web. UI.HtmlControls;


public partial class Invoice: System. Web. UI.Page

{

    protected void Page_Load (object sender, EventArgs e)

    {

        if (Request. Params ["ID"]! = null)

        {

            Guid id = new Guid (Request. Params ["ID"]);


            if (CheckedInvoices. GetResult (id) .Length == 0)

            {

                phInvoice. Controls. Add (new LiteralControl (" Please, wait... "));

                Response. AddHeader ("Refresh", "5");

}

            else

            {

                phInvoice. Controls. Add (new LiteralControl (CheckedInvoices. GetResult (id)));

                CheckedInvoices. Remove (id);

}

}

        else

        {

            phInvoice. Controls. Add (new LiteralControl (" the identifier of the waybill is not specified. "));

}

}

}


The circuit is very simple - on page Default.aspx occurs postbehk, during this moment the new unique identifier which is passed a method, vypolnjaemumo in separate process is created. After that there is a readdressing on page Invoice.aspx where there is a check on identifikutoru (peredanomu in GET search) in table CheckedInvoices, whether there are no there data. If the data no, the heading, informing is sent a browser about necessity to make Refresh if the result has appeared to the user the result is deduced, and a key udaljaesja from the khehsh-table as it is not necessary any more.






© Web Development Company Conkurent, LLC 2008-2009. All rights reserved.