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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:06:15+00:00 2026-05-22T18:06:15+00:00

I have declared in C# a static public int then that int is suplyed

  • 0

I have declared in C# a static public int then that int is suplyed to a thread in it’s constructor the thread’s job is very simple to increment it but it doesn’t happen
Here I declare the static value:

class Global
{
    static public  int hardcap = 100;
    public int speed;
    static public Semaphore myhitpoints = new Semaphore(1, 1);
    static public Semaphore oponenthitpoints = new Semaphore(1, 1);
   static  public int mhp = 100;
    static public int ohp = 100;
    static public int mmana = 0;
    static public int omana = 0;
  public static Charm dragonblade = new   Charm(10, 30, 3, myhitpoints, oponenthitpoints, mhp, ohp, "dragon blade", mmana);
  public  static  Charm dragonshield = new Charm(30, 10, 5, myhitpoints, oponenthitpoints, mhp, ohp, "dragon shield", mmana);
    public static Charm b1charm;
    public static  Charm b2charm;
    public static Opponent enemy;

}

class ManaWell
    {
        int mana_regen;
        int cap = 1000;
        int target;
        public ManaWell(int x, int y)
        {
           mana_regen = x;
            target = y;
        }
        public void Refill()
        {
            while (true)
            {
               // if (this.target + mana_regen <= cap)
                if (target+mana_regen<cap)
                {
                    Thread.Sleep(3000);
                    target += mana_regen;
                    MessageBox.Show(target.ToString());

                }
            }
        }
    }
 ManaWell mw1 = new ManaWell(20,Global.mmana);
        ManaWell mw2 = new ManaWell(20,Global.omana);

        Thread tmw1 = new Thread(new ThreadStart(mw1.Refill));
        Thread tmw2 = new Thread(new ThreadStart(mw2.Refill));

        tmw1.Start();
        tmw2.Start();

So target works fine but y won’t increase.

  • 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-22T18:06:16+00:00Added an answer on May 22, 2026 at 6:06 pm

    When you create your ManaWell object and pass in a variable, it will only be the variable’s value that is assigned to target. So when you add to target, you are doing only that; the passed-in variable will not be affected (as you’re seeing.)

    If you’re really passing in a public static int, then to increase it, just do math on it directly (and you don’t even have to pass it in):

    MyClass.MyStaticInt += aNumber;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

WorkAround: I have declared a class level Public static variable and initialized with a
I have a c# static class that I have declared as internal. I also
I have a windows forms application, where I have declared some static variables. On
Suppose I have a static variable declared inside a function in C. If I
If I have a collection of static constants that I want to declare centrally
I have declared one variable in xslt, assigned some value to it but while
I have declared: queue<int, list<int> > Q After a series of calls: Q.push(37); Q.pop();
I have declared a class as class DCFrameListener : public FrameListener, public OIS::MouseListener, public
I have declared a DLL import in my C# program that looks like this:
Say I have a struct declared like the following: public struct Test { public

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.