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 694513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:51:52+00:00 2026-05-14T02:51:52+00:00

LastInput.time is an Integer and m_idleTime is an Integer too. This line sometimes generates

  • 0

LastInput.time is an Integer and m_idleTime is an Integer too. This line sometimes generates an Overflow exception, I think that this happens when both values are big negative values.

(Environment.TickCount - lastInput.time) > m_idleTime

How can I avoid that? With casting?

(CType(Environment.TickCount,Long) - CType(lastInput.time,Long)) > m_idleTime

Or maybe with this cast?

CType((Environment.TickCount - lastInput.time),Long) > m_idleTime

Thanks in advance.

EDIT: I’m using the GetLastInputInfo method to check how many time has been the computer idle. I have declared the return value from the call this way:

    <StructLayout(LayoutKind.Sequential)> Public Structure StructLastInputInfo
        <MarshalAs(UnmanagedType.U4)> Dim size As Integer
        <MarshalAs(UnmanagedType.U4)> Dim time As Integer
    End Structure

So I think that when the Environment.TickCount returns a negative value the same will happen with the GetLastInputInfo, right? But then the values of the substraction will be wrong because they will be negative, so as far as I see the problem what should be done is this:

Math.Abs(CType(Environment.TickCount, Long) - CType(lastInput.time, Long)) > m_idleTime

What do you think?

  • 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-14T02:51:52+00:00Added an answer on May 14, 2026 at 2:51 am

    That’s how I fixed the problem:

                currentTime = BitConverter.ToUInt32(BitConverter.GetBytes(Environment.TickCount), 0) #'' This code can fail with 1 tick error when changing the sign of one item.
                lastInputTime = BitConverter.ToUInt32(BitConverter.GetBytes(lastInput.time), 0)
    
                If currentTime - lastInputTime > m_idleTime Then
    

    This code works because you get the bytes of the Integer and just use them as if they where an UInteger, this does not throw OverflowException.

    The only problem I’ve seen is that you have a 1 unit error when doing the subtraction when the sign of one item has changed, not sure about what is happening but anyway having 1 tick error is not an issue.

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

Sidebar

Related Questions

I am writing a C# Project that is relatively simple. Think Public Web Terminal.
I have an array. One of the values in that array responses[1] is an
I have to write a program that accepts a sequence of average daily temperatures
I'm Trying to write a Cisco Command Line Parser to have an automated Graphical
In my C# Windows Forms application, I have a user control that contains other
Continuously ask the user to enter numbers until the user enters a number that
When I enter input that satisfies everything and doesn't trigger any of my errors,
I have a line made of input s and span s which should represent
This should be really simple. I want to repeat a string in Ruby this
What can I do that shortcuts for menu items don't overwrite those from local

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.