I wanna implement the revolving slash while the process is executing

  • Thread starter Thread starter antonyliu2002
  • Start date Start date
A

antonyliu2002

I have a Windows console application, which takes around 3 minutes to
complete the execution.

I am interested in implementing something animate while users are
waiting for the process to complete.

If you have experience with Linux/Unix, you should be very familiar
with the revolving slash ( / ) or the growing dots ( ...... ), which
you normally see, when a process is taking some time.

I guess I may have to implement 2 threads. One does the real dirty
work behind, the other displays the revolving slashes (maybe it is a
combination of --, / and \) or grows the dots.

Any idea how to implement this fun stuff? Thanks.
 
if your doing gui i would do somthing Graphical
else
back in the old dos days i did the used the \ / -

based on what ur doing....a process bar is a nice thing
if you can calculate the time...or size for units
otherwise when the calculations are not possible

a disabled text box colord as the window is ..can be used also filling it
and scrolling it with dots....

i used 1 progressbar and filled it one way and reversed it the other way and
forward and back....til lthe process was finished

send 1 thread off to do the work
and main or new 2 thread to work the progress bar...

there's some ideas
MJ
 
I have a Windows console application, which takes around 3 minutes to
complete the execution.

I am interested in implementing something animate while users are
waiting for the process to complete.

If you have experience with Linux/Unix, you should be very familiar
with the revolving slash ( / ) or the growing dots ( ...... ), which
you normally see, when a process is taking some time.

I guess I may have to implement 2 threads. One does the real dirty
work behind, the other displays the revolving slashes (maybe it is a
combination of --, / and \) or grows the dots.

Any idea how to implement this fun stuff? Thanks.

How fancy do you want?

Here's a simple example:

static void Main()
{
Thread thread = new Thread(ThreadStart(DoWork));
char[] rgchBusy = new char[] { '-', '\', '|', '/' };
int ichBusy = 0;

thread.Start();

// The thread that does the work will set WorkDoneWaitHandle,
// an instance of a WaitHandle, when it's done.
while (WorkDoneWaitHandle.WaitOne(1000))
{
Console.WriteLine("\r" + rgchBusy[ichBusy]);
ichBusy = (ichBusy + 1) % rgchBusy.Length;
}
}
 
I have a Windows console application, which takes around 3 minutes to
complete the execution.
I am interested in implementing something animate while users are
waiting for the process to complete.
If you have experience with Linux/Unix, you should be very familiar
with therevolvingslash( / ) or the growing dots ( ...... ), which
you normally see, when a process is taking some time.
I guess I may have to implement 2 threads. One does the real dirty
work behind, the other displays therevolvingslashes (maybe it is a
combination of --, / and \) or grows the dots.
Any idea how to implement this fun stuff? Thanks.

How fancy do you want?

Here's a simple example:

static void Main()
{
Thread thread = new Thread(ThreadStart(DoWork));
char[] rgchBusy = new char[] { '-', '\', '|', '/' };
int ichBusy = 0;

thread.Start();

// The thread that does the work will set WorkDoneWaitHandle,
// an instance of a WaitHandle, when it's done.
while (WorkDoneWaitHandle.WaitOne(1000))
{
Console.WriteLine("\r" + rgchBusy[ichBusy]);
ichBusy = (ichBusy + 1) % rgchBusy.Length;
}
}


Thanks. I tried your trick. It works. I was using the backspace
character \b, which did not help. The \r absolutely helped.

How about the growing dots (......)?

Of course, simply growing the dots is easy, but I am not sure how to
remove all those dots and then start growing from scratch on the same
line again. Could anyone of you shed some light on this? Thanks.
 
Thanks. I tried your trick. It works. I was using the backspace
character \b, which did not help. The \r absolutely helped.

How about the growing dots (......)?

Of course, simply growing the dots is easy, but I am not sure how to
remove all those dots and then start growing from scratch on the same
line again. Could anyone of you shed some light on this? Thanks.

It would be pretty much the same as the "spinning line", except that
rather than writing the \r character each time, you'd only write it when
you'd written as many periods as make up the line you want (presuambly,
no more than there are characters wide on your console :) ).

Pete
 
I dug out this thread through google because I want to do the same. I am trying to understand Peter Duniho's code shown below:

static void Main()
{
Thread thread = new Thread(ThreadStart(DoWork));
char[] rgchBusy = new char[] { '-', '\', '|', '/' };
int ichBusy = 0;

thread.Start();

// The thread that does the work will set WorkDoneWaitHandle,
// an instance of a WaitHandle, when it's done.
while (WorkDoneWaitHandle.WaitOne(1000))
{
Console.WriteLine("\r" + rgchBusy[ichBusy]);
ichBusy = (ichBusy + 1) % rgchBusy.Length;
}
}

Where the DoWork method which is passed to the ThreadStart constructor? I suppose DoWork is the method which continuously spit out '-', '\', '|', '/' onto the console in the same cursor position?

And what is WorkDoneWaitHandle? I can't find anything about this from MSDN.

Any input? Thanks.


I have a Windows console application, which takes around 3 minutes to
complete the execution.

I am interested in implementing something animate while users are
waiting for the process to complete.

If you have experience with Linux/Unix, you should be very familiar
with the revolving slash ( / ) or the growing dots ( ...... ), which
you normally see, when a process is taking some time.

I guess I may have to implement 2 threads. One does the real dirty
work behind, the other displays the revolving slashes (maybe it is a
combination of --, / and \) or grows the dots.

Any idea how to implement this fun stuff? Thanks.

How fancy do you want?

Here's a simple example:

static void Main()
{
Thread thread = new Thread(ThreadStart(DoWork));
char[] rgchBusy = new char[] { '-', '\', '|', '/' };
int ichBusy = 0;

thread.Start();

// The thread that does the work will set WorkDoneWaitHandle,
// an instance of a WaitHandle, when it's done.
while (WorkDoneWaitHandle.WaitOne(1000))
{
Console.WriteLine("\r" + rgchBusy[ichBusy]);
ichBusy = (ichBusy + 1) % rgchBusy.Length;
}
}
 
I dug out this thread through google because I want to do the same. I am trying to understand Peter Duniho's code shown below:

static void Main()
{
Thread thread = new Thread(ThreadStart(DoWork));
char[] rgchBusy = new char[] { '-', '\', '|', '/' };
int ichBusy = 0;

thread.Start();

// The thread that does the work will set WorkDoneWaitHandle,
// an instance of a WaitHandle, when it's done.
while (WorkDoneWaitHandle.WaitOne(1000))
{
Console.WriteLine("\r" + rgchBusy[ichBusy]);
ichBusy = (ichBusy + 1) % rgchBusy.Length;
}
}

Where the DoWork method which is passed to the ThreadStart constructor? I suppose DoWork is the method which continuously spit out '-', '\', '|', '/' onto the console in the same cursor position?

And what is WorkDoneWaitHandle? I can't find anything about this from MSDN.

If I have understood what you want correctly then I would do it like:

int ix = 0;
Timer t = new Timer(delegate(object o) { Console.Write(@"-\|/"[ix++%4] +
"\r"); }, null, 0, 250);
Thread.Sleep(10000); // simulate something that takes a long time
t.Dispose();

Arne
 
Back
Top