0

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

John G
  • 1
  • 4
  • You can use asynchronous methods. https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/ – Florian Jan 04 '23 at 14:31

1 Answers1

0

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);
        });
Mukul Keshari
  • 495
  • 2
  • 7
  • Thank you Mukul. your upoded code really worked for me. for some reason the OnComplete code wouldnt work from the "Thread.sleep(2000);" line so added the last 3 lines outside of the loop. any ideas why this would be? and thanks again! – John G Jan 05 '23 at 17:35