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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:20:02+00:00 2026-05-29T10:20:02+00:00

I am working in C#, winform and Mysql. (Visual Studio 2010). In my project

  • 0

I am working in C#, winform and Mysql. (Visual Studio 2010).

In my project all menustrip items are invisable. At the login time its visible which menustrip item user rights. For that i invisible all menu strip,. And I code for visible the menustrip items.

But its take too much time. more then 5 minutes. So I have Few Questions.

  1. How I find this coding execution time?. (My Code Below)….
  2. Is any special tool is there?.
  3. How to Reduce the time with effective code?
  private void menuActive(ToolStripItemCollection items)
        {
            hp.getConnStr();
            MySqlConnection connection = new MySqlConnection(hp.myConnStr);
            MySqlCommand command = connection.CreateCommand();
            MySqlDataReader Reader;
            command.CommandText = "select menu_key from mcs_menu_rights where userid ='"+userId+"'";
            connection.Open();
            Reader = command.ExecuteReader();
            while (Reader.Read())
            {
                foreach (ToolStripMenuItem item in items)
                {
                    if (item.Name == Reader[0].ToString())
                    {
                        item.Visible = true;
                    }
                    else
                    {
                        menuActive(item.DropDown.Items);
                    }
                }
            }
            connection.Close();
        }
  • 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-29T10:20:02+00:00Added an answer on May 29, 2026 at 10:20 am

    You could profile, but there are some definite improvements I can see straight off:

    Seperate out your recusive function away from the database query. This way you query the database once. Note that it’s not doing exactly the same, but I’m not sure what that table looks like so you’ll have to test it.

    private void menuActive(ToolStripItemCollection items) 
        { 
            hp.getConnStr(); 
            MySqlConnection connection = new MySqlConnection(hp.myConnStr); 
            MySqlCommand command = connection.CreateCommand(); 
            MySqlDataReader Reader; 
            command.CommandText = "select menu_key from mcs_menu_rights where userid ='"+userId+"'"; 
            connection.Open(); 
            Reader = command.ExecuteReader(); 
            while (Reader.Read()) 
            {
                var nameFromDB = Reader[0].ToString();
                setMenuActiveByName(items, nameFromDB);
            }
            connection.Close(); 
        }
    
        //This is the recursive bit, but doesn't re-enquire the database
        private void setMenuActiveByName(ToolStripItemCollection items, string name) 
        {
                foreach (ToolStripMenuItem item in items) 
                { 
                    if (item.Name == name) 
                    { 
                        item.Visible = true; 
                    } 
                    else 
                    {
                        setMenuActiveByName(item.DropDown.Items, name); 
                    } 
                }
        } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)
I'm working on a WPF application with Visual Studio 2010 Express. I have a
Working in the visual designer of a WinForm project , when one selects an
I am working with CrystalDecisions.CrystalReports.Engine.ReportDocument in WinForms in Visual Studio 2008. Right now when
I want to pass myConnString in all forms. ( I am working in winform
I'm working on a WinForm project, using BackgroundWorker , for a data extraction procedure,
I'm working on a WinForm application. I've implemented data-access logic into a library project
I'm working on a project where I need to open a winform from a
My team working in a project using Winforms application(c#) & MSSQL 2005 as database.
I am working on a little WinForm app and have been trying to find

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.