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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:57:58+00:00 2026-06-02T06:57:58+00:00

I have a test application, with a class TestSeq and a method Go(), which

  • 0

I have a test application, with a class TestSeq and a method Go(), which consist of such blocks:

            _writer.WriteLine("Doing foo action...");
            var stopwatch = Stopwatch.StartNew();
            // foo - some work here
            stopwatch.Stop();
            _writer.WriteDone("Results of foo action.", stopwatch.Elapsed);

In “some work” I have different calls to WCF client (CRUD actions, filters, etc.).

So, a lot of code repeating, and obviously some refactor should be done here. I think about creating a class TestAction, but I dont know what is the best way to put that “some work” part in it.

It’s seems to me that this is quite simple problem, but I just don’t know what keywords should I search for. So, I’d be glad to see answers with just a keyword (pattern name or something) or link.

  • 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-02T06:58:05+00:00Added an answer on June 2, 2026 at 6:58 am

    I’m sure there are more, but off the top of my head, you can probably this boiler plate code in two ways.

    Method 1: Use the using syntax to wrap the code of interest

    class MeasuredOperation : IDisposable
    {
        Stopwatch stopwatch;
        string message;
    
        public MeasuredOperation(string message)
        {
            Console.WriteLine("Started {0}", message);
            stopwatch = Stopwatch.StartNew();
            this.message = message;
        }
    
        public void Dispose()
        {
            stopwatch.Stop();
            Console.WriteLine("Results of {0} Elapsed {1}", this.message, this.stopwatch.Elapsed);
        }
    }
    
        static void Main(string[] args)
        {
            using (new MeasuredOperation("foo action"))
            {
                // Do your action
            }
        }
    

    Method 2: Creating a new function and passing in your block of code as a delegate

    static void MeasuredAction(string message, Action action)
    {
        Console.WriteLine("Started {0}", message);
        var stopwatch = Stopwatch.StartNew();
        action();
        stopwatch.Stop();
        Console.WriteLine("Results of {0} Elapsed {1}", message, stopwatch.Elapsed);
    }
    
    static void Main(string[] args)
    {
        MeasureAction(delegate()
        {
            // do work
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one demo application to check select for update query public class Test
I have a very simple application test in which I want to drag and
I have created a console test application which creates, an object & calls 2
I have a C# .Net console application which calls a C++ .Net class library.
I have a simple test application: Model: public class Counter { public int Count
I'm working on a test application using Spring MVC. I have a Person class
I have created small test web application which makes use of LINQ to SQL.
Lets say i have a page called https://url.com/test and https://url.com/test2 class Test extends Application
I have a simple test application (C# console application) that does an HTTP GET
I have made a simple test application for the issue, two winforms each containing

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.