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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:58:07+00:00 2026-06-14T11:58:07+00:00

I have several methods that have the folling structure: public void doWhatever() { methodToPrepareEnvironment();

  • 0

I have several methods that have the folling structure:

    public void doWhatever()
    {
     methodToPrepareEnvironment();
     // do something
     methodToResumeEnvironment();
    }

All my “doWhatever”-type methods call these prepare/resume methods and there is only 1 prepare and 1 resume method called by all these doWhatever methods. Is there a better way to achieve this without having to put a call to the prepare and resume methods at the beginning and end of all my doWhatever methods? I have the feeling I am missing something extremely basic here. Please note, the doWhatever methods cannot be combined, they each need to be independent and they each need to prepare the environment, do some tasks and then resume the environment.

Thank you.

  • 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-14T11:58:11+00:00Added an answer on June 14, 2026 at 11:58 am

    With strategic use of access modifiers you can ensure external calls are always preceded and followed by method calls with little repetition like so:

    public void DoWhatever()
    {
        DoAction(DoingWhatever);
    }
    
    private void DoingWhatever()
    {
        // ...
    }
    
    private void DoAction(Action action)
    {
        methodToPrepareEnvironment();
    
        action();
    
        methodToResumeEnvironment();
    }
    

    An Action is a delegate that represents a method with no return value.

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

Sidebar

Related Questions

I have several methods that have a return type IEnumerable<T> . These methods are
I want to have a class Utils, that will have several methods used all
I have several private methods that I use in authentication of all pages in
I have a simple ASP.NET hosted WCF Service that has several methods that all
I have several methods that deal with DB and all of them start by
I have several methods that populate a SQLCommand objects parameter collection from an object
I have a class that currently has several methods that take integer parameters. These
Basically, if I have a method (or several methods) that I want to expose
I have some methods that are used by several classes. My idea was to
I have several models that need to call a method that takes a particular

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.