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

  • Home
  • SEARCH
  • 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 7787253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:36:18+00:00 2026-06-01T20:36:18+00:00

I know, this question already been asked in many places repeatedly. But I’ve tried

  • 0

I know, this question already been asked in many places repeatedly. But I’ve tried to google it and check this site for solution, but still come short. I’m still encountering this issue even after using all of the suggested solutions.

Basically, I have two separate programs. The function of each program is something like below.

  1. ProgramA – Function: Constantly update to the source file(txt)
  2. ProgramB* – Function: Constantly copy the source file to destination location.

With ProgramB, I want to sort of simulate doing the ctrl+c operation. Hence I am trying to archive where by I can update the file and operator can copy it as well.

Here is what I’ve tried so far. Below is sample program to test the functionality.

ProgramA

static void Main(string[] args)
{
    // just prepare the data
    List<string> tempList = new List<string>();
    for(int i = 0; i < 50000; i++)
    {
        tempList.Add(string.Format("xxx_{0}", i.ToString()));
    }

    try
    {
        // just to simulate constart update
        for (int j = 0; j < 20000; j++)
        {
            using (FileStream file = new FileStream(tmpFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                using (StreamWriter sw = new StreamWriter(file))
                {
                    foreach (string tmpName in tempList)
                    {
                        sw.WriteLine(tmpName);
                    }
                    sw.Close();
                }
                file.Close();
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex);
        Console.ReadKey();
    }
}

ProgramB

static void Main(string[] args)
{
    string source = @"C:\temp\test.txt";
    string dest = @"C:\temp\dest\test.txt";
    while (true)
    {
        try
        {
            File.Copy(source, dest, true);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            Console.ReadKey();
        }
    }
}
  • 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-01T20:36:20+00:00Added an answer on June 1, 2026 at 8:36 pm

    Instead of using File.Copy, try using a FileStream and copying the bits yourself. The above code will get an error, as File.Copy does not specify what FileShare permissions it sets on the file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that this question has already been asked, but I have strange problem
I know this question has been asked before, but I've tried everything I could
I know this question has been asked already but I would like to solve
Okay, I know this question have been asked plenty of times already, but I
I know this question already have been asked. But I could not find any
I know this question has already been asked and answered, but it didn't help
I know this question has been asked many times on SO, but none of
I know that this question has been asked multiple times already , but I
I know this question has already been asked, but my question is more general
I know this question has been asked elsewhere but reading the already given answers

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.