Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6327755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:20:10+00:00 2026-05-24T17:20:10+00:00

Currently I have this code all throughout my program in many places such as

  • 0

Currently I have this code all throughout my program in many places such as form resizing events, splitter moving events, document size changes, et cetera:

hsc.Value = (int)MathHelper.Clamp(hsc.Value, 0, hsc.Maximum - hsc.LargeChange + 1);
vsc.Value = (int)MathHelper.Clamp(vsc.Value, 0, vsc.Maximum - vsc.LargeChange + 1);

I’m wondering whether or not it would be better to just put it in a main loop because my program has a drawing code that is called whenever the application goes idle (very often).

The disadvantage of having this code in events is because it is code repetition and I might miss an event. The disadvantage of having it in the loop is that it may not be needed each loop and it is wasted processor cycles. However, it may be premature optimization because it probably would not be noticeable to the end-user.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:20:11+00:00Added an answer on May 24, 2026 at 5:20 pm

    What framework are you using? (WinForms, WPF, Silverlight, etc)

    If it’s in every Window / Form / View / UserControl then you might consider putting this functionality in a base class and pointing all these events to event handlers in the base class.

    Neither of your solutions seem correct – you shouldn’t be redrawing in a ‘main loop’ if nothing has changed, and you shouldn’t be copy/pasting duplicated code throughout your app.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently in my program in about 10 control event handlers I have this code:
We currently have code like this: Dim xDoc = XDocument.Load(myXMLFilePath) The only way we
Using dotnet 2.0. I currently have code like this : DataView dv = new
Is there a better way to do this jquery code? Currently I have to
There is probably is simple fix for this but I currently have code similar
I currently have this XAML Code: <ListView x:Name=listFeedSearch Margin=-548.856,95.333,0,7.667 HorizontalAlignment=Left Width=542.5 RenderTransformOrigin=0.5,0.5 ItemsSource={Binding SearchCollection}>
Currently I have this code: selectorRect.X = (e.X + hscTileset.Value) / tileLayer.TileSize * tileLayer.TileSize;
I currently have this line of code which has been working for the past
I have this little code which lists all matches of items that contains the
I currently have this code in the page/div when you load it without anything

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.