Understanding Conditional Branches in While Statements

Asked 2 years ago, Updated 2 years ago, 379 views

Sorry for the rudimentary question.
We are currently doing count processing by turning while statements and sorting them into folders.
You are trying to print characters on the console screen when the count value is a multiple of 60.
The count value should increase every second, but if you don't press Enter, it goes on and on. Does the phrase "Processing is finished. Please any key!" appear?
If there is no key input for a multiple of 60, I would like to submit the wording only once.

while(true)
{
if(NativeThinkear.TG_GetValueStatus(connectionID, NativeThinkear.DataType.TG_DATA_ATTENTION)!=0)
                    {
                        US>//#string fileName=";
                        Timer timer = new Timer (1000);

                        var count = 0;
                        int foldercount = 1;
                        timer.Elapped+=(sender,e)=>
                        {

                            String foldercountStr=foldercount.ToString();
                            if (count <20)
                            {
                                fileName=fileNameFolder+foldercountStr+"data0to20.txt";
                                count++;

                            }
                            else if (count <40)
                            {
                                fileName=fileNameFolder+foldercountStr+"data21to40";
                                count++;

                            }
                            else if (count <60)
                            {
                                fileName=fileNameFolder+foldercountStr+"data41to60";
                                count++;

                            } else if (count %60 == 0)
                            {
                                fileName=fileNameFolder+foldercountStr+"dataothers";
                                Console.Beep (10000,500);
                                Console.WriteLine("Processing is finished.Please any key!");
                                ConsoleKeyInfo input=Console.ReadKey();
                                String strA = "Enter";
                                if(strA.Equals(input.Key.ToString())))
                                {
                                    count++;
                                }
                                
                            }
                            else
                            {
                                fileName=fileNameFolder+foldercountStr+"dataothers";
                                count = 0;
                                timer.Stop();
                            }
}

c# visual-studio

2022-09-30 22:00

1 Answers

The code is incomplete, but if you omit the contents of timer.Elapped

while(true){
    if(NativeThinkear.TG_GetValueStatus(connectionID, NativeThinkear.DataType.TG_DATA_ATTENTION)!=0){
        US>//#string fileName=";
        Timer timer = new Timer (1000);

        var count = 0;
        int foldercount = 1;
        timer.Elapped+=(sender,e)=>{};
    }
}

It looks like it has a structure that.Of course, this loop itself does not have the element of waiting a second, and it keeps spinning indefinitely (timer.Elapsed runs every second, but it has nothing to do with while loops).

Each loop generates a timer object and each timer starts counting one second in parallel.


2022-09-30 22:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.