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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:40:25+00:00 2026-06-12T01:40:25+00:00

I am trying to wrap a bunch of methods that interact with a API

  • 0

I am trying to wrap a bunch of methods that interact with a API server to test how long each takes.

For instance I want to wrap these methods:

    public DCResultOfValidateSiteForUser ValidateSiteForUser(int UserId, int UserType, int SiteId)
    {
        return Service.ValidateSiteForUser(UserId, UserType, SiteId);
    }
    public DCResultOfIsSystemInStandby IsSystemInStandby()
    {
        return Service.IsSystemInStandby();
    }

Here is what I want to wrap around the above methods:

    public static T TestPerf<T>(Action action)
    {
        Stopwatch sw = new Stopwatch();
        sw.Start();

        action();

        sw.Stop();

        StackTrace stackTrace = new StackTrace();
        StackFrame stackFrame = stackTrace.GetFrame(1);
        MethodBase methodBase = stackFrame.GetMethod();

        TextWriter tw = new StreamWriter("perfLog.txt", true);
        string s = String.Format("{0} {1}{2,15}", String.Format("{0:M/d/yyyy HH:mm:ss}", DateTime.Now), methodBase.Name, sw.Elapsed);
        tw.WriteLine(s);
        tw.Close();

        return default(T);
    }

However, since an Action returns void. I have then then do:

    public DCResultOfValidateSiteForUser ValidateSiteForUser(int UserId, int UserType, int SiteId)
    {
        TestPerf<DCResultOfValidateSiteForUser>(() => Service.ValidateSiteForUser(UserId, UserType, SiteId));
        return Service.ValidateSiteForUser(UserId, UserType, SiteId);
    }
    public DCResultOfIsSystemInStandby IsSystemInStandby()
    {
        TestPerf<DCResultOfIsSystemInStandby>(() => Service.IsSystemInStandby());
        return Service.IsSystemInStandby();
    }

What I want is:

    public DCResultOfIsSystemInStandby IsSystemInStandby()
    {
        return TestPerf<DCResultOfIsSystemInStandby>(() => Service.IsSystemInStandby());
    }

I do not want to have to put the stopwatch code into every method as there are 100’s.

I appreciate any help that can be provided.

Thanks

  • 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-12T01:40:26+00:00Added an answer on June 12, 2026 at 1:40 am

    This should compile and not execute the methods twice:

    public DCResultOfValidateSiteForUser ValidateSiteForUser(int UserId, int UserType, int SiteId)
    {
        DCResultOfValidateSiteForUser result = null;
        TestPerf<DCResultOfValidateSiteForUser>(() => result = Service.ValidateSiteForUser(UserId, UserType, SiteId));
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use jQuery to basically wrap a bunch of CSS modifications
I am trying to wrap a generated series of elements that are created on
I'm trying to get a bunch of div's to wrap around an image, but
So I have a bunch of images (ImageViews) that I'm trying to scale appropriately
Im trying to wrap my head around this, using Jquery I want to browse
I'm trying to wrap my head around ServiceStack, and while it claims that it
I'm trying to use facet_wrap to plot a bunch of dataset as scatterpoints, each
Trying to wrap my head around JTA and have arbitrarily chosen Bitronix as the
Trying to wrap my head around the jQuery .not() function, and running into a
Im trying to wrap my head around MVVM. I understand a lot of it,

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.