The problem of httpcontext.current under multi-threading

Source: Internet
Author: User

A text log is required in the project, and multithreading is used in order to speed up the response.

However, the previous method does not support multi-threaded, program run error.

Trace code Discovery hint HttpContext is empty.

1.httpcontext.current represents the current HttpRequest corresponding context object

HttpContext.Current change in different HttpRequest.
This means that data saved with HttpConext.current.items cannot be passed across pages.

2.httpcontext.current can only return a value from a thread that is currently executing

3.httpcontext.current
This will be related to Thread.currentcontext, when the multi-threaded switch
The httpcontext.current will be replaced with the context of the current thread.

General will use the System.Web.HttpContext.Current.Server.MapPath method, then it can not be used so it is possible to use

System.IO.Path.Combine (AppDomain.CurrentDomain.BaseDirectory, strpath);

Another is the file operation do not use static method , will cause file occupancy and so on.

The problem of httpcontext.current under multi-threading

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.