Navigation X
ALERT
Click here to register with a few steps and explore all our cool stuff we have to offer!



   917

C# Best way to save lines from multiple threads with less cpu load and efficiency

by DragZer - 22 December, 2021 - 12:58 PM
This post is by a banned member (DragZer) - Unhide
DragZer  
Registered
182
Posts
104
Threads
5 Years of service
#1
I tried the normal one, which simply append lines as per they hit. But I am seeing exceptions "hits.txt" used by other program or smthg. It maybe coz of many hits at a time so to overcome this issue I did a thing to enqueue the hit and then run a seperate task to save enqueued ones seperately but that was taking high AF cpu load. :) If you can help me out thx
[Image: sticker.png]
This post is by a banned member (FanTaZyX) - Unhide
FanTaZyX  
Registered
523
Posts
352
Threads
6 Years of service
#2
(This post was last modified: 30 December, 2021 - 09:43 AM by FanTaZyX. Edited 1 time in total.)
Use an object to lock like this for example :
 
Code:
lock (locker)
{
 // Your code to save hits
}

...

private static object locker = new object();
 
This post is by a banned member (BabiKoqi) - Unhide
BabiKoqi  
Coder
1.236
Posts
132
Threads
6 Years of service
#3
id recommend using a lock statement similar to this: 
Code:
lock(Lock)
   File.AppendAllText(Results, line + Environment.NewLine);

private static object Lock = new object();
[Image: LF32t6E.gif]
ONLYHUB.TO | #1 QUALITY | ONLYFANS ACCOUNTS WITH BALANCE | $100 | $200 | $300 | $400 | + WITH CC
paid until 27/06/2025.

[Image: Yagaboo.gif]
Donate BTC: bc1qpd2a44cvj7f2y3k7q2vfac3t2qnrv2amsg7kkp

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
or
Sign in
Already have an account? Sign in here.


Forum Jump:


Users browsing this thread: 1 Guest(s)