Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Is it possible to refresh the console application in c# like windows application?Or is there any alternative for the same purpose?Kindly tell me how to do that?

Thanks.
Posted
Comments
Mehdi Gholam 20-Oct-11 2:58am    
What do you mean by refresh?
sreenathpktr 20-Oct-11 3:00am    
i mean reloading from the first line.
Mehdi Gholam 20-Oct-11 3:17am    
View my answer.
sreenathpktr 20-Oct-11 3:27am    
Thank you..I fixed my problem without the refreshing.
Vivek Krishnamurthy 20-Oct-11 3:07am    
Why do you want to restart the application ? Can you not just restart the functionality?

No - a Console application does not have an Application object in teh same way that a Windows one does.
You can duplicate the effect though:
C#
static void Main(string[] args)
    {
    while (RunMyApp(args))
        {
        }
    }
static bool RunMyApp(string[] args)
    {
    ...
    return true;   // Restart
    ...
    return false;  // End program
    }
 
Share this answer
 
Comments
RaviRanjanKr 20-Oct-11 3:18am    
My 5+
sreenathpktr 20-Oct-11 3:27am    
Thank you..I fixed my problem without the refreshing.this coding is very useful also.
Well you can clear the screen.

Try with

Console.Clear();


method.

UPDATE:

after seeing other peoples replay maybe I got a question wrong.
Check this example:

C#
class Program
    {
        static void Main(string[] args)
        {
            Console.Clear();

            bool done = false;
            while (!done)
            {
                ShowMenu();

                ConsoleKeyInfo keyHit = Console.ReadKey(true);

                Console.Clear();

                switch (keyHit.KeyChar)
                {
                    case '1':
                        SimpleArraySort();
                        break;
                    case '2':
                        SimpleListSort();
                        break;
                    case '5':
                        PerformanceTest();
                        break;
                    case '9':
                        done = true;
                        break;
                    default:
                        Console.WriteLine("Please enter a valid option. \r\n");
                        continue;
                }
            }
        }
     }



Cheers
 
Share this answer
 
v3
Comments
sreenathpktr 20-Oct-11 3:27am    
Thank you..I fixed my problem without the refreshing.
Mario Majčica 20-Oct-11 3:31am    
How did you did it? Did this helped?
sreenathpktr 20-Oct-11 3:38am    
I just used another way...simply goto method used.Your is needed for another process..Thank you very much..
 
Share this answer
 
Comments
sreenathpktr 20-Oct-11 3:22am    
No...that's not it..Thank you for replying.
Console output is limited if you want to see what is going on the easiest and best option is to redirect the output to a file and view that in notepad etc.
c:\> consoleapp.exe > log.txt
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900