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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:37:52+00:00 2026-06-10T03:37:52+00:00

public partial class _Default : System.Web.UI.Page { private static Stopwatch timer = new Stopwatch();

  • 0
public partial class _Default : System.Web.UI.Page
{
    private static Stopwatch timer = new Stopwatch();
    Thread timeThread = new Thread(timeKeeper);
    private static int min = 0, sec = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void startstop_Click(object sender, EventArgs e)
    {
        timeThread.Start();
        if(timer.IsRunning()) {timer.Stop}
        else timer.Start();
    }
    private static void timeKeeper()
    {
        while (timer.IsRunning)
        {
            mydelegate();
        }
    }
    private static void mydelegate()
    {
        _Default temp = new _Default();
        temp.Update();
    }
    private void Update()
    {
        min = timer.Elapsed.Minutes;
        sec = timer.Elapsed.Seconds;
        time.Text = min + ":" + sec;
    }
}

what i want to do is have a button that controls the a stopwatch, when you click it it starts, click it again it stops. I figured the best way to do it is with a thread if i want the time.text display to continue update and to be able to click the button still. when i run the above program it gets to time.text = min + “:” + sec; and throws a nullreferenceexception. Any help on how to fix this would be greatly appreciated. I am semi new to programming in C#/asp.net.

Is there a better way of working with delegates then this. I have spent hours looking up how to use them with not many usual/easy to understand tutorials or blogs

  • 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-06-10T03:37:54+00:00Added an answer on June 10, 2026 at 3:37 am

    I’m not sure where to begin.

    Remember you are programming a webpage, and every call to a server result in a new webpage life cycle on the server. So using threads in a webpage will not result in the correct behaviour.

    To get the kind of behaviour you want, you’ll have to do the timer and click handling on the client instead of the server. You can use jQuery to facilitate in this. One other option is to use ajax if you have to keep the server up-to-date.

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

Sidebar

Related Questions

I have the following code: public partial class queryTerm : System.Web.UI.UserControl { private static
hi i have the follow code: public partial class _Default : System.Web.UI.Page { int
I have very simple: [PrincipalPermission(SecurityAction.Demand, Role = Administrator)] public partial class _Default : System.Web.UI.Page
Here is my code: public partial class Image : System.Web.UI.Page { protected void Page_Load(object
I'm trying to call RoleEnvironment.GetConfigurationSetting(SOMEKEY) like so: public partial class AzureBasePage : System.Web.UI.Page {
In the following master.cs code: public partial class Default : System.Web.UI.MasterPage { protected void
Given this class public partial class Default : Page { private IRepository repo; ...
I have a page that is setup like this public partial class _Default :
With this code: public partial class Form1 : Form { private static readonly int
I have a web project like: namespace Web { public partial class _Default :

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.