+ 1
Loading Animation in c# Console
hi Friends , is there any function in c# wich animate a loading Sequenz ?? If Not is it possible to do it in a tricky way?? IT has to be in the simple console not with graphics and so on. Ive tried it with visual Studio (iam a beginner) .
7 Réponses
+ 1
Hi Korhall,
try to use a timer in combination with a plain text like "Loading " and printed dots ('.'):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading; // mandatory for timer
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Loading ");
// Create instance of timer ticking every 1000 ms
Timer t = new Timer(TimerCallback, null, 0, 1000);
// Wait for the user to hit <Enter>
Console.ReadLine();
t = null; // Timer destroyed
}
// callback function for timer, which prints the dots
static void TimerCallback(Object o) => Console.Write(".");
}
}
+ 1
wow i will try it . if u could see what i have done to simulate a loading process hahhaha iam happy that my code is private i thank you so much i will try it. sounds nice to me
+ 1
ich sehe gerade dass du aus Deutschland kommst. Danke auf jeden fall, das sieht vielversprechend aus!
+ 1
Hi Korhall, please try timer.dispose();
Greetings
Peter
+ 1
Hi Korhall,
sorry, it has to be
t.dispose();
example:
Console.Write("Loading ");
Timer t = new Timer(TimerCallback, null, 0, 1000);
// Wait for the user to hit <Enter>
Console.ReadLine();
t.Dispose();
Console.WriteLine("Timer disposed!");
Console.ReadLine();
Peter
0
yeah it works. But still have 1 problem, The Timer wont end and it will also write Loading infinitely
0
Thank you peter,
but i dont know how to use timer.dispose();