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

  • Home
  • SEARCH
  • 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 8303531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:34:14+00:00 2026-06-08T17:34:14+00:00

I have a recursive function and two events ( Going_in and Coming_out ). I

  • 0

I have a recursive function and two events (Going_in and Coming_out).

I use the Going_in event to increment a progressbar every time the function calls itself and I use Coming_out to decrement the progressbar every time the function returns from recursion.

Now i have to combine Going_in and Coming_out into one event.
How can I do that?

Thanks in advance!

Here is part of the code.

Form1.cs

   .....
   void ProgressBar_increment(object sender, EventArgs e)
    {
        progressBar1.Value++;

    }
    void ProgressBar_decrement(object sender, EventArgs e)
    {
        progressBar1.Value--;
    }
   public void button2_Click(object sender, EventArgs e)
    {
        initialize();
        label3.Visible = false;
        int wait_time = telltime();
        int number = reading();

        Facto mth;


        mth = new Facto(label3, wait_time, progressBar1);

        mth.Going_in += new EventHandler(ProgressBar_increment);
        mth.Coming_out += new EventHandler(ProgressBar_decrement);


        int result = mth.Factorial(number);

        string display = result.ToString();


        label3.Visible = true;

        label3.Text = display;
    }

Facto.cs

public event EventHandler Going_in;
public event EventHandler Coming_out;

........

public int Factorial(int number_to_calculate)
    {


        int Result;

        if (Going_in != null)
        {
            Going_in(this, new EventArgs());
        }


         System.Threading.Thread.Sleep(wait_time);
        if (number_to_calculate == 0)
        {
            if (Coming_out != null)
            {
                Coming_out(this, new EventArgs());
            }

            return 1;

        }
        else
       {
           Result = (number_to_calculate * Factorial(number_to_calculate - 1));
           if (label_for_output != null)
           {
               label_for_output.Visible = true;
               label_for_output.Text = Result.ToString();
               label_for_output.Update();
           }
           else 
               Console.WriteLine(Result);

       }


        if (Coming_out != null)
        {
            Coming_out(this, new EventArgs());
        }
        System.Threading.Thread.Sleep(wait_time);



        return Result;
    }
  • 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-08T17:34:15+00:00Added an answer on June 8, 2026 at 5:34 pm

    That is what the EventArgs are for.
    Put some variable in the EventArgs object (or create your own for this purpose) from where you can determine whether to increment or decrement (enum maybe?)

    I.e. (possible pseudo code alert)

    if (Going_in != null)
    {
       CustomEventArgs cea = new CustomEventArgs();
       cea.Type = Type.Decrement;
       Going_in(this, cea);
    }
    

    And in your event do something like:

    void ProgressBar_DoProgress(object sender, CustomEventArgs e)
     {
        if(e.Type == Type.Increment)
           progressBar1.Value++;
    
        if(e.Type == Type.Decrement)
           progressBar1.Value--;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple recursive function RCompare() that calls a more complex function Compare()
How can I combine these two functions into one recursive function to have this
I have a recursive function working on a list, the function contains a loop
I have a recursive function reading a table of contents of documents from a
I have a recursive function which does a sort of tree process where each
Lets say I have a recursive function that creates lists within lists. It return
I am currently trying to build a program where I have a recursive function
After some recursive function I have an array: first iteration: Array ( [category_id] =>
I have some sort of recursive function, but I need to parse a string,
Is it possible to have a PHP function that is both recursive and anonymous?

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.