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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:18:22+00:00 2026-05-27T13:18:22+00:00

I have dll method that should be QoSed – this method should be called

  • 0

I have dll method that should be “QoSed” – this method should be called maximum 100 times per second.:

    private static extern int ExecTrans(int connectionId);

This method used only in one place in program so it’s ok to qos this place.
I need separate “qos counter” for each connectionId. So ExecTrans(1) and ExecTrans(2) should go to different counters.

At first iteration I would like to count how often method is called (for each connectionId). I.e. I want to have “live statistics”. There are two approach:

- allow to exceed limitiation for a short period. for example allow "100 transaction from 0 to 1 second, 100 transaction from 1 to 2 seconds and 200 transactions from 0.5 to 1.5 second".
- at any second interval transactions should not exceed 100.

For now I don’t care which of these methods to use but I would select one creating less “overhead”. I want qos to add as less “extra-work” as possible because it’s trading software sensitive to every 0.1 ms.

As for first approach I think I can use something like that (pseude-code, probably stats and curStats should be made thread-safe):

private int[] stats      // statistic to display to user
private int[] curStats;  // statistic currently collection

OnOneSecondElapsed(object source, ElapsedEventArgs args) {
    foreach (conId : connIds) {
        stats[conId] = curStats[conId];
        curStats[conId] = 0;
    }
}

myMethod {
    ......
    ExecTrans(conId);
    ++curStats[conId];
    ......
}

As for second approach…. is it possible to make a collection where objects life for exactly one second and after a second disappear? Then every time I will add the next object to a collection unless collection contains 100 objects.

What do you think? I’m not familar with C# library files so probably I’m missing some useful classess, probably you can suggest another approach.

  • 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-05-27T13:18:23+00:00Added an answer on May 27, 2026 at 1:18 pm

    A first approach:

    • Use a ConcurrentQueue<DateTime>
    • Before every request, check the size of the queue. If > 100, cancel the request
    • If < 100, enqueue the current DateTime and execute the request
    • In a background thread, every 0.1 second, remove entries older than 1 second

    It should be fairly efficient, but:

    • Since there’s no locking between the time you check the queue count and the time you enqueue, you may sometimes get slightly over 100 requests per second
    • Since the background thread executes every 0.1 second, if you receive 100 requests at the same time, it may block the queue for up to 1.1 seconds. Adjust the sleep time as needed.

    I may be wrong but I don’t think there’s a perfect solution. Basically, the more precise the system is, the more overhead there is. You have to adjust the parameters depending on your needs.

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

Sidebar

Related Questions

Setup: I have a COM DLL that calls a method inside a managed C#
I have a .dll file and in there, there's a method called A. When
I have DLL and application that will call some function in this dll. For
I have a Library ( DLL ) that has a method with the following:
I have an unmanaged DLL that gets called from .NET with pre-allocated buffers to
I have a class which uses a method in user32.dll: [System.Runtime.InteropServices.DllImport(user32.dll)] private static extern
I have a method in my native dll, that I want to use. The
I have this method that I need to call and use in my application,
I have a method I want to import from a DLL and it has
I have created a .NET DLL which makes some methods COM visible. One method

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.