views:

20

answers:

1

Hi everybody, I am in a situation, in which my program needs to do processing and then wait for some interval, let's say 5 seconds and the do the same processing again.

I don't know how to implement the logic.

I have developed a logic, the code is below:

private void ProcessEmail()
    {
        PprocessEmail:;

        //Do whatever you want

        System.Threading.Thread.Sleep(5000);
        goto ProcessEmail;
    }

What this code does: I only have to call this method once, it will do the processing then wait for 5 seconds and then again process.

So far above code is working fine, but i have heard using "goto" statements is not considered good in programming.

I want to know, will there be any side effect of this code or is there any other efficient way of doing the same thing.

+2  A: 

Look at loops. This Wiki article might be a good place to start for the theory.

If it's C#, what you'd use is a while(true) that would loop forever.

ho1
Hi, guys thanks for the reply, i do know about the loop. But is there any other efficient method than looping and as i have done. You understand the kind of functionality i want.
nccsbim071
@nccsbim071: I'm slightly confused, the functionality you want is looping. The goto is just doing it in an uglier way. I don't know, but it wouldn't surprise me if internally the loop and the goto might be represented exactly the same way and I can't imagine that there would be a more efficient way of looping than via a loop of some kind...
ho1
I think you guys are right i will implement the while.
nccsbim071