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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:10:16+00:00 2026-06-04T19:10:16+00:00

Say I’m writing a piece of software that simulates a user performaning certain actions

  • 0

Say I’m writing a piece of software that simulates a user performaning certain actions on a system. I’m measuring the amount of time it takes for such an action to complete using a stopwatch.

Most of the times this is pretty straighforward: the click of a button is simulated, some service call is associated with this button. The time it takes for this service call to complete is measured.

Now comes the crux, some actions have more than one service call associated with them. Since they’re all still part of the same logical action, I’m ‘grouping’ these using the signalling mechanism offered by C#, like so (pseudo):

var syncResultList = new List<WaitHandle>();

var syncResultOne = service.BeginGetStuff();
var syncResultTwo = service.BeginDoOtherStuff();

syncResultList.Add(syncResultOne.AsyncWaitHandle); 
syncResultList.Add(syncResultTwo.AsyncWaitHandle);

WaitHandle.WaitAll(syncResultList.ToArray());

var retValOne = service.EndGetStuff(syncResultOne);
var retValTwo = service.EndDoOtherStuff(syncResultTwo);

So, GetStuff and DoOtherStuff constitute one logical piece of work for that particular action. And, ofcourse, I can easily measure the amount of time it takes for this conjuction of methods to complete, by just placing a stopwatch around them. But, I need a more fine-grained approach for my statistics. I’m really interested in the amount of time it takes for each of the methods to complete, without losing the ‘grouped’ semantics provided by WaitHandle.WaitAll.

What I’ve done to overcome this, was writing a wrapper class (or rather a code generation file), which implements some timing mechanism using a callback, since I’m not that interested in the actual result (save exceptions, which are part of the statistic), I’d just let that return some statistic. But this turned out to be a performance drain somehow.

So, basically, I’m looking for an alternative to this approach. Maybe it’s much simpler than I’m thinking right now, but I can’t seem to figure it out by myself at the moment.

  • 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-04T19:10:17+00:00Added an answer on June 4, 2026 at 7:10 pm

    This looks like a prime candidate for Tasks ( assuming you’re using C# 4 )

    You can create Tasks from your APM methods using MSDN: Task.Factory.FromAsync

    You can then use all the rich TPL goodness like individual continuations.

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

Sidebar

Related Questions

Say I have a SSI script that uses exec, or a PHP script that
Say that I have a singleton class (Downloader) responsible for downloading and persisting files.
Say I have two types of objects, Apples and Chainsaws . A user is
Say I have a LINQ-to-XML query that generates an anonymous type like this: var
Say I have a higher kinded type SuperMap[Key[_],Value[_]]`. Suppose now that I had something
Say I have 2 div s with the same CSS class that are stacked
Say I have function with_foo that takes a block, and wrap it around a
Say, if we already have aScreen that points to the main screen, by UIScreen
Say I have an System.String[] type object. I can query the type object to
Say you built a recommendation engine that would recommend you live TV shows for

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.