C# Console project. How do i repeat 3 messages during file.copy action

56 Views Asked by At

FYI this is my 1st ever C# Project so forgive me any shortcomings

This is my current code is..

            if (File.Exists(InstallFolder + StrFilename))
            {
                Console.WriteLine("\r\nSQS App Found");
                File.Delete(InstallFolder + StrFilename);
                Console.WriteLine("Updating the Quotation System, Please Wait...");
                File.Copy(StrServerFolder + StrFilename, InstallFolder + StrFilename);
                Console.WriteLine("Done. Launching the SQS App...");
                Thread.Sleep(2000);
                System.Diagnostics.Process.Start(InstallFolder + StrFilename);
                Environment.Exit(0);
            }

My Target is to display
"Updating the Quotation System, Please Wait." then overwrite this line with "Updating the Quotation System, Please Wait.." and final over write "Updating the Quotation System, Please Wait..."
repeat these messages until "File.Copy(StrServerFolder + StrFilename, InstallFolder + StrFilename);" has completed.
it may be easier to split the message in 2 parts with {.} {..} {...} at the end of the string

i have tried various apporaches tried google adding text to my CS file found on line, gave me errors in VS ( probably be cause i did'nt understand the structure.

Any help would be appreciated its a small programme i like to keep it a simple as possibe.

TIA

1

There are 1 best solutions below

1
Mukul Keshari On

Here is the updated (example) code which might work for you

        Console.WriteLine("\r\nSQS App Found");
        var awaiter = Task.Run(() =>
        {
            if (!File.Exists(InstallFolder + StrFilename)) return;
            File.Delete(InstallFolder + StrFilename);
            File.Copy(StrServerFolder + StrFilename, InstallFolder + StrFilename);
        }).GetAwaiter();

        var i = 1;
        while (!awaiter.IsCompleted)
        {
            Console.WriteLine("Updating the Quotation System, Please Wait" + new string('.', i));
            Thread.Sleep(100);
            i++;
        }

        awaiter.OnCompleted(() =>
        {
            Console.WriteLine("Done. Launching the SQS App...");
            Thread.Sleep(2000);
            System.Diagnostics.Process.Start(InstallFolder + StrFilename);
            Environment.Exit(0);
        });