In Asp.net web development, we often encounter the following problem: Slow user operation response.
This situation may occur because user operations are time-consuming operations. . Net program is designed in the background when the user submits the operation. After the processing is complete, the operation result is returned to the user. In a smaller system, this design is simple and easy, and the performance does not have much problems. However, in a larger system, this design will give users a poor operation experience, this affects users' impression of the system.
In the system I previously implemented, there are generally two ways to deal with this situation: 1. record user operations directly to the backend database for regular scanning by the background program. Ii. Use Asp.net's timed processing method to process the data directly on the Web server layer.
There is no big difference between the two methods. The first method mainly requires a background program to complete the scanning.
Here I will briefly introduce the second method.
Its core processing is system. Threading. Timer. This scheduled class can be used to periodically execute user submission operations in the background,
Its Usage:
System. Threading. timercallback T = new system. Threading. timercallback (your solution );
System. Threading. Timer T = new system. Threading. Timer (T, null, 1000,5000 );
This section indicates that the specified proxy is called every five seconds after 1 second of startup.
In specific implementation, I define three classes.
1. bkexecitem is used to save the user's submitted operations. It can also be serialized to the disk to avoid the loss of key background tasks.
2. bkexec is used for execution. It calls the method specified in bkexecitem through reflection. In addition, it also maintains
The first-out queue <bkexecitem> records all background processing items.
3. bkmanager initializes the timer and configures the module parameters.
Well, we will summarize it here for the time being. Next time, I will post the code for your reference.