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

The Archive Base Latest Questions

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

I am writing tracing class to find the execution time of modules/methods. I have

  • 0

I am writing tracing class to find the execution time of modules/methods. I have a class like this

public class Trace
    {
        static Dictionary<string, Stopwatch> watches = null;

        static Trace()
        {
            Dictionary<string, Stopwatch> watches = new Dictionary<string, Stopwatch>();
        }

        public static void Start(string key, string losgMessage)
        {
            try
            {
                if (!watches.Keys.Contains(key))
                {
                    Stopwatch watch = new Stopwatch();
                    watch.Start();
                    watches.Add(key, watch);
                }
            }
            catch
            {
            }
        }

        public static void Stop(string key, Object logMessage, string sessionId)
        {
            try
            {

                if (!watches.Keys.Contains(key))
                {
                    Stopwatch watch = watches[key];
                    watch.Stop();
                    //log goes here
                }
            }
            catch
            {
            }
        }
    }

since wcf is multithreaded environment and the ‘watches’ static variable scope is application level, If some one(new rqst from the differnt client) tries to execute the same method with same key i will not consider it and trace it. So what would be the best option in this case. Any suggestion would be helpful.

edit : I am current appending sessionId with key. Cant i resolve this issue without session id

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

    Can’t I resolve this issue without session Id

    From the information provided, I would say no. If you have concurrent requests executing the same function call then you are going to get duplicate entries. The only way to avoid this is to ensure all keys are unique. I actually think using the session ID is required anyway, otherwise how can you map the function to the request?

    Also, Dictionary isn’t thread-safe (at least for writes), I would recommend using a ConcurrentDictionary.

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

Sidebar

Related Questions

I'm writing an expense tracking program. At the moment I have three class Lineitem
I'm writing bug tracking software in PHP, and today I saw this in another
I am looking into writing a web-based vehicle tracking system. The framework I have
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
I have a database table and a corresponding entity class (POCO with change tracking
I'm writing a LaTeX document in vim, and I have it hard wrapping at
I have spent most of my development career writing backend code, or front-end apps
I have been writing a growing code base in Haskell. My problem is that
Im writing sql query and i have issue which i cannot fix. I'm trying
I have a class representing a finite-state machine, which should run in a forever

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.