C # multithreaded write file, often write unsuccessful

Source: Internet
Author: User

In the project, do a text log function

In order not to affect the page response speed, so the use of multi-threading, at the time of testing, the risk of file writing is often unsuccessful, after some setbacks,

Discover th. IsBackground = true; a background thread is not a child of the main thread, which is represented as a child thread of the main thread, and the child threads are closed together if the main thread is closed.

After commenting out the code, the query is normal.

 Public voidAsync_writelog_desc (ObjectLOGOBJCT,stringOldobject,ObjectnewObject) {Thread th=NewThread (NewParameterizedthreadstart (THEADINVOK_WRITELOG_DESC)); Logentity LG=Newlogentity (); LG.LOGOBJCT=logobjct; Lg.oldobject=Oldobject; Lg.newobject=NewObject; //th. IsBackground = true; background thread is not a child thread of the main threadth.        Start (LG); }

C # multithreaded write file, often write unsuccessful

Related Article

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.