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!