Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8465865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:10:27+00:00 2026-06-10T15:10:27+00:00

I put lock on a few lines which are supposed to get cookie files

  • 0

I put lock on a few lines which are supposed to get cookie files and read them, but I see sometimes an error saying file already in use! So not sure whats going wrong…

Code:

private Object cookieLock = new Object();

main{
    for (int j = 0; j < maxThreads; j++)
        {
            //   Thread thread = new Thread(new ThreadStart(startPosting2(worker)));
            Thread thread = new Thread(() => postingFunction2());
            thread.IsBackground = true;
            thread.Start();
        }
    }

public void postFunction2()
{
 string tmpUsername = string.Empty;
 string[] array2 = null;
   try
    {
      lock (cookieLock)
       {
          array2 = File.ReadAllLines(tmpUsername + ".txt");
       }
    }
   catch(Exception ex)
    {
      TextWriter sUrl = new StreamWriter("readingSameCookieFile.txt", true);
      sUrl.WriteLine(exp.ToString());
      sUrl.Close();
    }
}

Am I doing anything wrong? These lines are executed by 20-100 threads simultaneously, I do not see it much but I do see it some time, so wondering why!

TXT FILE ERROR:

System.IO.IOException: The process cannot access the file 'C:\Users\Administrator\My Projects\Bot Files\2 Message Poster Bot\MessagePoster - NoLog - Copy\cookies\LaureneZimmerebner57936.txt' because it is being used by another process.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:10:29+00:00Added an answer on June 10, 2026 at 3:10 pm

    If you just want to overcome the problem you are having and are sure it’s not beeing written then you can use this function instead of File.ReadAllLines. The key is it the share options it gives FileShare.ReadWrite.

    private static string[] ReadAllLines(string fileName)
    {
      using (var fs = new FileStream(fileName, FileMode.Open,
                                               FileAccess.Read,
                                               FileShare.ReadWrite))
      {
        var reader = new StreamReader(fs);
        //read all at once and split, or can read line by line into a list if you prefer
        var allLines = reader.ReadToEnd().Split(new string[] { "\r\n", "\r", "\n" },
                                                StringSplitOptions.None);
        return allLines;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I put my files in the directory assets. how do I get them? I
This post explains how to put file write lock on regular files. But is
Put them all in one separate folder structure or along with classes which implements
I put a TileGroup in a BorderContainer and set the width to 100%, but
i'd like to put a kind of lock file in the user's home directory
I want to use java.nio.channels.FileChannel to read from a file, but I want to
Recently I am doing one project in emulator lock and unlock screen. I put
been pulling my hair out about this for ages! Trying to put a lock
I need to read from a Stream and put the buffer that was read
If there is an item that has a read lock on a table for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.