Click here to Skip to main content
15,906,329 members
Home / Discussions / C#
   

C#

 
AnswerRe: Opinion on the following please... Pin
Ian Shlasko27-Apr-11 3:19
Ian Shlasko27-Apr-11 3:19 
GeneralRe: Opinion on the following please... Pin
Paladin200027-Apr-11 3:30
Paladin200027-Apr-11 3:30 
GeneralRe: Opinion on the following please... Pin
Rob Philpott27-Apr-11 3:36
Rob Philpott27-Apr-11 3:36 
GeneralRe: Opinion on the following please... Pin
Paladin200027-Apr-11 3:43
Paladin200027-Apr-11 3:43 
AnswerRe: Opinion on the following please... Pin
PIEBALDconsult27-Apr-11 14:30
mvePIEBALDconsult27-Apr-11 14:30 
QuestionGauge control to show an angle variation Pin
AlexB4727-Apr-11 3:08
AlexB4727-Apr-11 3:08 
AnswerRe: Gauge control to show an angle variation Pin
Ian Shlasko27-Apr-11 3:17
Ian Shlasko27-Apr-11 3:17 
QuestionAttributes in C# Pin
Loithuxua27-Apr-11 0:15
Loithuxua27-Apr-11 0:15 
AnswerRe: Attributes in C# PinPopular
Pete O'Hanlon27-Apr-11 0:21
mvePete O'Hanlon27-Apr-11 0:21 
GeneralRe: Attributes in C# Pin
Keith Barrow27-Apr-11 0:46
professionalKeith Barrow27-Apr-11 0:46 
GeneralRe: Attributes in C# Pin
Pete O'Hanlon27-Apr-11 1:01
mvePete O'Hanlon27-Apr-11 1:01 
GeneralRe: Attributes in C# Pin
Keith Barrow27-Apr-11 1:24
professionalKeith Barrow27-Apr-11 1:24 
GeneralRe: Attributes in C# Pin
Not Active27-Apr-11 2:29
mentorNot Active27-Apr-11 2:29 
GeneralRe: Attributes in C# Pin
Keith Barrow27-Apr-11 2:32
professionalKeith Barrow27-Apr-11 2:32 
GeneralRe: Attributes in C# Pin
Pete O'Hanlon27-Apr-11 2:36
mvePete O'Hanlon27-Apr-11 2:36 
GeneralRe: Attributes in C# Pin
Not Active27-Apr-11 2:40
mentorNot Active27-Apr-11 2:40 
GeneralRe: Attributes in C# Pin
Wayne Gaylard27-Apr-11 0:55
professionalWayne Gaylard27-Apr-11 0:55 
AnswerRe: Attributes in C# Pin
ambarishtv28-Apr-11 5:45
ambarishtv28-Apr-11 5:45 
QuestionTime-Out for Loop in C#? Pin
JP_Rocks26-Apr-11 23:33
JP_Rocks26-Apr-11 23:33 
AnswerRe: Time-Out for Loop in C#? Pin
V.26-Apr-11 23:41
professionalV.26-Apr-11 23:41 
AnswerRe: Time-Out for Loop in C#? Pin
Wayne Gaylard26-Apr-11 23:48
professionalWayne Gaylard26-Apr-11 23:48 
AnswerRe: Time-Out for Loop in C#? Pin
Pete O'Hanlon27-Apr-11 0:02
mvePete O'Hanlon27-Apr-11 0:02 
First of all, there is no implicit loop operation that breaks out at a specified time interval. You'll have to code it yourself.

Secondly, as your loop depends on reaching a value or a timeout being reached, a for loop is not the appropriate choice - it is designed to work with a fixed number of iterations. In this case, I would choose to use a while loop instead. Then you could do something like the following:
C#
Stopwatch watch = new Stopwatch();
int count = 0;
do
{
  if (!watch.IsRunning)
  {
    watch.Start();
  }
  PerformSomeLongRunningOperation();
} while (++count < 10 && watch.Elapsed <= TimeSpan.FromSeconds(2) );
watch.Stop();

Forgive your enemies - it messes with their heads


My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility


QuestionXML Search Pin
DJ24526-Apr-11 20:40
DJ24526-Apr-11 20:40 
AnswerRe: XML Search Pin
Pete O'Hanlon26-Apr-11 22:04
mvePete O'Hanlon26-Apr-11 22:04 
GeneralRe: XML Search Pin
DJ24526-Apr-11 22:34
DJ24526-Apr-11 22:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.