Multiple Threads in ASP. NET to display the operation progress

Source: Internet
Author: User

 


The operation progress must be displayed when a long operation is executed. This can be done using multiple threads.

1 define a thread operation class threadclass
Class has an attribute field to save the operation status, there is a method for the thread to call
2. instantiate this class in Asp.net processing, save the class in the session, create a new thread using the method in the class, and start the thread.
3. Obtain the status
Obtain the class from the session and view the value of the attribute field in the class.


The operations to obtain the status are also different: Ajax method and IFRAME refresh or overall refresh; If Ajax method is used, it is recommended to call the ashx file, because the server performs less operations and the speed is fast.


// A page_load method or a method that AJAX can call or the processrequest method in ashx


Threadsta Load =   New Threadsta (ID );
Context. session [ " Downsta " ] = Load;

System. Threading. thread t =   New System. Threading. Thread ( New System. Threading. threadstart (load. Start ));
T. Start ();

 

// Thread class
Public   Class Threadsta
{
// State
Public   Int Number;

Private   Int ID;
Public Threadsta ( Int ID)
{
This . ID = ID;
}
Public   Void Start ()
{
// Proccess
}
}

Read status from session

Threadsta down = Context. session [ " Downsta " ] As Threadsta;
If (Down ! = Null )
{
// Get down. Number as State
}

Over!

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.