473,395 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to introduce delay in C#..

Hi groups,

How i can introduce some milliseconds delay in application. How i can do
achieve this...

let me clearly say...
(1) I'm displaying slices of medical images.
For framerate [2x/4x/6x] - for this i'm loading 2+ slices, 4+ slices in loop
to have cine impact..-> Ok working
(2) But if i want to reduce the speed...how i can introduce delay inbetween
slices..[ -2x/-4x/-6x]...-> ?????

I'm not using Threading..so i cannot think of Sleep.

Maheshkumar.R
http://spaces.msn.com/members/cyberiafreak


Nov 17 '05 #1
11 21219
Hi,

To make some delay in c#,use the for Loops,

for(i=0;i<=delay;i++);

Adjust the delay value according to ur delay time.Here delay is a long int.

"Maheshkumar.R" wrote:
Hi groups,

How i can introduce some milliseconds delay in application. How i can do
achieve this...

let me clearly say...
(1) I'm displaying slices of medical images.
For framerate [2x/4x/6x] - for this i'm loading 2+ slices, 4+ slices in loop
to have cine impact..-> Ok working
(2) But if i want to reduce the speed...how i can introduce delay inbetween
slices..[ -2x/-4x/-6x]...-> ?????

I'm not using Threading..so i cannot think of Sleep.

Maheshkumar.R
http://spaces.msn.com/members/cyberiafreak


Nov 17 '05 #2
No aravind. I know this shortcut. But I'm looking something in Keyword
perspective or any inbuilt function from C#..

Mahesh
"Aravind" <Ar*****@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
Hi,

To make some delay in c#,use the for Loops,

for(i=0;i<=delay;i++);

Adjust the delay value according to ur delay time.Here delay is a long int.
"Maheshkumar.R" wrote:
Hi groups,

How i can introduce some milliseconds delay in application. How i can do
achieve this...

let me clearly say...
(1) I'm displaying slices of medical images.
For framerate [2x/4x/6x] - for this i'm loading 2+ slices, 4+ slices in loop to have cine impact..-> Ok working
(2) But if i want to reduce the speed...how i can introduce delay inbetween slices..[ -2x/-4x/-6x]...-> ?????

I'm not using Threading..so i cannot think of Sleep.

Maheshkumar.R
http://spaces.msn.com/members/cyberiafreak


Nov 17 '05 #3
Aravind <Ar*****@discussions.microsoft.com> wrote:
To make some delay in c#,use the for Loops,

for(i=0;i<=delay;i++);

Adjust the delay value according to ur delay time.Here delay is a long int.


No, that's a terrible way of delaying! It puts the processor into a
tight loop!

If the OP wants to do something on a regular basis in a UI, then a
Timer is the best bet:
http://www.pobox.com/~skeet/csharp/threads/timers.shtml
To delay a single thread, use Thread.Sleep - but don't do this in the
UI thread, or it will make the UI unresponsive.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
Hi, the easiest and best way would be to use a timer. Timers are objects
that can be set up to tell you when a specified period of time has elapsed.
It's certainly a better solution than just looping or doing a Thread.Sleep.

Using a TimerCallBack delegate, you specify which method you want the timer
to call. Like so...

using System.Threading;

class
{
Timer tmr;

public void ShowSlide( object state )
{
// Do some stuff to show a slide
}

public void StartSlideshow()
{
TimerCallBack tcb = new TimerCallback( ShowSlide );
timer = new Timer( tcb, null, 1000, 1000 );
}
}

Obviously you can change this to be able to specify what time period you
want to leave between slides etc. Any problems post back.

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton
"Maheshkumar.R" <ma*********@sninform.com> wrote in message
news:Oe*************@TK2MSFTNGP15.phx.gbl...
Hi groups,

How i can introduce some milliseconds delay in application. How i can do
achieve this...

let me clearly say...
(1) I'm displaying slices of medical images.
For framerate [2x/4x/6x] - for this i'm loading 2+ slices, 4+ slices in loop to have cine impact..-> Ok working
(2) But if i want to reduce the speed...how i can introduce delay inbetween slices..[ -2x/-4x/-6x]...-> ?????

I'm not using Threading..so i cannot think of Sleep.

Maheshkumar.R
http://spaces.msn.com/members/cyberiafreak

Nov 17 '05 #5
So, its confirmed that we dont have any straight C# keyword or methods for
delay...?

I thought of going for Threading/timer initially but I wants to try
something else than this.

Here is my exact requirement :
As you all know fastforward in movie right..? 2x , 4x, 6x , 8x etc in VCD
player.
I have achieved fastforward by adding 'n+' slices..but when i comes to
Delaying i mean -2x , -4x, -6x etc...

I dont know how to solve this delaying...I mean i dont want to push this
function into threading or timer event or loop delay....let see if any one
proceeds this DELAY without delayinnnnnnnn......

Thanks for all your inputs..

Maheshkumar.R
http://spaces.msn.com/members/cyberiafreak

"Tim Haughton" <ti*********@gmail.com> wrote in message
news:k3*******************@fe08.news.easynews.com. ..
Hi, the easiest and best way would be to use a timer. Timers are objects
that can be set up to tell you when a specified period of time has elapsed. It's certainly a better solution than just looping or doing a Thread.Sleep.
Using a TimerCallBack delegate, you specify which method you want the timer to call. Like so...

using System.Threading;

class
{
Timer tmr;

public void ShowSlide( object state )
{
// Do some stuff to show a slide
}

public void StartSlideshow()
{
TimerCallBack tcb = new TimerCallback( ShowSlide );
timer = new Timer( tcb, null, 1000, 1000 );
}
}

Obviously you can change this to be able to specify what time period you
want to leave between slides etc. Any problems post back.

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton
"Maheshkumar.R" <ma*********@sninform.com> wrote in message
news:Oe*************@TK2MSFTNGP15.phx.gbl...
Hi groups,

How i can introduce some milliseconds delay in application. How i can do
achieve this...

let me clearly say...
(1) I'm displaying slices of medical images.
For framerate [2x/4x/6x] - for this i'm loading 2+ slices, 4+ slices in

loop
to have cine impact..-> Ok working
(2) But if i want to reduce the speed...how i can introduce delay

inbetween
slices..[ -2x/-4x/-6x]...-> ?????

I'm not using Threading..so i cannot think of Sleep.

Maheshkumar.R
http://spaces.msn.com/members/cyberiafreak


Nov 17 '05 #6
"Maheshkumar.R" <ma*********@sninform.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
So, its confirmed that we dont have any straight C# keyword or methods for
delay...?
There are lots of ways to delay your code, some good, some bad. Calling
Thread.Sleep is OK if you're not on your UI thread. A better way is to use
the timer. You could vary the speed of the playback simply by adjusting the
timer to fire at longer or shorter intervals.

I thought of going for Threading/timer initially but I wants to try
something else than this.
Any particular reason?

[Snip] I dont know how to solve this delaying...I mean i dont want to push this
function into threading or timer event or loop delay....let see if any one
proceeds this DELAY without delayinnnnnnnn......


What have you got against Threading, Timers and loops? If you want to delay
your code, you have got basically 2 options; if you're not on your UI
thread, call Sleep. But since you seem to be against using your own threads,
you're almost certainly on your UI thread. Your only option without
explicitly creating a thread is to use the Timer.

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton
Nov 17 '05 #7
This is a bad idea because it justs eats processor cycles that the machine
needs elsewhere.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Aravind" <Ar*****@discussions.microsoft.com> wrote in message
news:7B**********************************@microsof t.com...
Hi,

To make some delay in c#,use the for Loops,

for(i=0;i<=delay;i++);

Adjust the delay value according to ur delay time.Here delay is a long
int.

"Maheshkumar.R" wrote:
Hi groups,

How i can introduce some milliseconds delay in application. How i can do
achieve this...

let me clearly say...
(1) I'm displaying slices of medical images.
For framerate [2x/4x/6x] - for this i'm loading 2+ slices, 4+ slices in
loop
to have cine impact..-> Ok working
(2) But if i want to reduce the speed...how i can introduce delay
inbetween
slices..[ -2x/-4x/-6x]...-> ?????

I'm not using Threading..so i cannot think of Sleep.

Maheshkumar.R
http://spaces.msn.com/members/cyberiafreak


Nov 17 '05 #8
How about UI Thread...? I mean I have to create 'n' instances of forms in
'n' thread.
Will threading works for UI like Forms ...becoz my application is in
finishing stage....now got struck becoz of this delay probs.

Mahesh
"Tim Haughton" <ti*********@gmail.com> wrote in message
news:GV******************@fe05.news.easynews.com.. .
"Maheshkumar.R" <ma*********@sninform.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
So, its confirmed that we dont have any straight C# keyword or methods for delay...?
There are lots of ways to delay your code, some good, some bad. Calling
Thread.Sleep is OK if you're not on your UI thread. A better way is to use
the timer. You could vary the speed of the playback simply by adjusting

the timer to fire at longer or shorter intervals.

I thought of going for Threading/timer initially but I wants to try
something else than this.
Any particular reason?

[Snip]
I dont know how to solve this delaying...I mean i dont want to push this
function into threading or timer event or loop delay....let see if any one proceeds this DELAY without delayinnnnnnnn......


What have you got against Threading, Timers and loops? If you want to

delay your code, you have got basically 2 options; if you're not on your UI
thread, call Sleep. But since you seem to be against using your own threads, you're almost certainly on your UI thread. Your only option without
explicitly creating a thread is to use the Timer.

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton

Nov 17 '05 #9

"Maheshkumar.R" <ma*********@sninform.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
So, its confirmed that we dont have any straight C# keyword or methods for
delay...?

I thought of going for Threading/timer initially but I wants to try
something else than this.

Here is my exact requirement :
As you all know fastforward in movie right..? 2x , 4x, 6x , 8x etc in VCD
player.
I have achieved fastforward by adding 'n+' slices..but when i comes to
Delaying i mean -2x , -4x, -6x etc...

I dont know how to solve this delaying...I mean i dont want to push this
function into threading or timer event or loop delay....let see if any one
proceeds this DELAY without delayinnnnnnnn......


You don't have to push anything into threading, all you have to do is call
Thread.Sleep( delay); and the curent thread will suspend for delay
miliseconds (but not less than 10 or 15 or even more milliseconds).

Willy.
Nov 17 '05 #10
Ok, let me try this now...and write you back..thankz willy

Mahesh
"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...

"Maheshkumar.R" <ma*********@sninform.com> wrote in message
news:%2***************@TK2MSFTNGP09.phx.gbl...
So, its confirmed that we dont have any straight C# keyword or methods for delay...?

I thought of going for Threading/timer initially but I wants to try
something else than this.

Here is my exact requirement :
As you all know fastforward in movie right..? 2x , 4x, 6x , 8x etc in VCD player.
I have achieved fastforward by adding 'n+' slices..but when i comes to
Delaying i mean -2x , -4x, -6x etc...

I dont know how to solve this delaying...I mean i dont want to push this
function into threading or timer event or loop delay....let see if any one proceeds this DELAY without delayinnnnnnnn......


You don't have to push anything into threading, all you have to do is call
Thread.Sleep( delay); and the curent thread will suspend for delay
miliseconds (but not less than 10 or 15 or even more milliseconds).

Willy.

Nov 17 '05 #11
"Maheshkumar.R" <ma*********@sninform.com> wrote in message
news:u5**************@TK2MSFTNGP14.phx.gbl...
How about UI Thread...? I mean I have to create 'n' instances of forms in
'n' thread.
Will threading works for UI like Forms ...becoz my application is in
finishing stage....now got struck becoz of this delay probs.


I'm not entirely sure what you mean. Your UI will run on a thread. If you
run all of your code on the same thread as the UI, whenever your code is
'doing something', your UI will become unresponsive. It's good practice to
have your 'worker' code on a different thread to your UI *if* your 'worker'
code is doing something non-trivial.

If you're close to delivery and don't understand threading, I think you'd be
advised to talk to your project manager (et.al) and highlight the problem,
the solution, and the risk / delay associated with it.

Applications with a GUI that become unresponsive whenever the program is
doing something invariably look amateurish.

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton
Nov 17 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Des L. Davis | last post by:
System: Dell PowerEdge Server with 3 GB RAM, 2.4 GHz Celeron Software: Microsoft SQL Server 2000 Enterprise running on Windows 2003 Server Software: Microsoft SQL Server 2000 Enterprise running on...
11
by: Philip Parker | last post by:
any ideas? sleep(1) is far too long a delay, im looking for something in the range of 50-100 milliseconds at most. something which doesnt suck up cpu time too much would be nice. is there anything...
6
by: lucifer | last post by:
hi i need to insert delay in my program what function should i use the old delay is not supported by the VC6
20
by: Doug Thews | last post by:
I ran into an interesting re-pain delay after calling the Abort() method on a thread, but it only happens the very first time I call it. Every time afterward, there is no delay. I've got a...
7
by: mfeingold | last post by:
I am working on a system, which among other things includes a server and a ..net control sitting in an html page and connected to the server. I ran into a couple of problems, you guys might have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.