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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:09:24+00:00 2026-05-30T03:09:24+00:00

Sometimes its the simple things you thought you knew that make your head buzzz….

  • 0

Sometimes its the simple things you thought you knew that make your head buzzz….

I have an Asp.Net (forms) application that uses the static methods of a non-static class to do some processing on PostBack. Those methods need to return bool.

When there is an error in a static method I would prefer not to just throw the exception back up to the page-level code, but rather explicitly handle it in the static method and return false.

I may be over-thinking this but, if MyClass has a static ErrorMessage field, used in the Page like this:

if(!MyClass.DoSomething){
  errorLabel.Text = MyClass.ErrorMessage; //Static ErrorMessage is set 
}

am I right that ErrorMessage is effectively thread-safe since MyClass is non-static, the Page lives within a specific HttpContext and variables are destroyed on PostBack?

Is there a reason not, or, a better way?

  • 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-30T03:09:26+00:00Added an answer on May 30, 2026 at 3:09 am

    If ErrorMessage is set by DoSomething, that is not thread safe. If you get a context switch after the if test and before the assignment, it could get reassigned by another thread. Static fields are static independent of whether the containing class is static or not.

    Get rid of your C-style return code and throw an exception on error instead.

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

Sidebar

Related Questions

I have an application that uses NHibernate as its ORM and sometimes it experiences
I've got a program that periodically updates its database schema. Sometimes, one of the
Sometimes it's difficult to describe some of the things that us programmers may think
I have been reading about Quicksort and found that sometimes it' s referred to
I have recently started using coffeescript with Rails and I am finding that sometimes
Sometimes its necessary to code in AS2 to target Flash Player 8, so we're
Sometimes when I set a breakpoint and start debugging its color changes from red
Unfortunately, sometimes the only way to debug a program is by going through its
I have a div behind the main div. Sometimes it appears and sometimes it's
I have a very simple file upload PHP script. I am testing with a

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.