In chapter 27, the CLR has an instruction in the form of a C # book written by Richter:
You can use the ExecutionContext class to suppress the flow of the execution context, thereby improving the performance of your application. Profit from the preliminary preparation can be very significant for the server application.
The following are an example:
CallContext.LogicalSetData("Name", "Jeffrey");
ThreadPool.QueueUserWorkItem(
state => Console.WriteLine("Name={0}", CallContext.LogicalGetData("Name")
));
The second part follows:
ExecutionContext.SuppressFlow();
ThreadPool.QueueUserWorkItem(
state => Console.WriteLine("Name={0}", CallContext.LogicalGetData("Name")
));
ExecutionContext.RestoreFlow();
Result:
Name=Jeffrey
Name=
The child flow has lost its context (in the second part of the example), because the side effect parameters are lost after suppression. But we saved the processor time (in my case, about 10% of the CPU time was saved).
- Do you use the ExecutionContext.SuppressFlow () method to reduce processor processing time?
- , , ?
- ?