Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Function for n number of users.

Function for n number of users.

Scheduled Pinned Locked Moved C#
questiondatabasebusinesssaleshelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zafar Sultan
    wrote on last edited by
    #1

    How can I execute a function for a huge number of users? Say 5000. In my web application there are more then 5000 users. they all get their revenue based on the business generated by them. The problem is: The revenue has to be generated daily. If I create a form with text box as user id and a button and on click of the button the function to generate the revenue execute, it is going to take forever for all the users as the query contains deleting, updating, inserting, and other tasks. So how can I create a function that executes for all the users.

    M P 2 Replies Last reply
    0
    • Z Zafar Sultan

      How can I execute a function for a huge number of users? Say 5000. In my web application there are more then 5000 users. they all get their revenue based on the business generated by them. The problem is: The revenue has to be generated daily. If I create a form with text box as user id and a button and on click of the button the function to generate the revenue execute, it is going to take forever for all the users as the query contains deleting, updating, inserting, and other tasks. So how can I create a function that executes for all the users.

      M Offline
      M Offline
      mahmoudinirat
      wrote on last edited by
      #2

      you can pass the where as parameter if no user (specific user ) pass ""(nothing)

      Z 1 Reply Last reply
      0
      • M mahmoudinirat

        you can pass the where as parameter if no user (specific user ) pass ""(nothing)

        Z Offline
        Z Offline
        Zafar Sultan
        wrote on last edited by
        #3

        I think you are not getting my point. There is no issue with query. The only thing is that the administrator has to manually create commission for every user. I want this functionality automated. That means the function for creating commission should run for every member at once.

        M 1 Reply Last reply
        0
        • Z Zafar Sultan

          I think you are not getting my point. There is no issue with query. The only thing is that the administrator has to manually create commission for every user. I want this functionality automated. That means the function for creating commission should run for every member at once.

          M Offline
          M Offline
          mahmoudinirat
          wrote on last edited by
          #4

          i think your problem how to call all users ?? if yes then the problem in your query and the solution as i replied before if No then i am not understand your problem stell

          1 Reply Last reply
          0
          • Z Zafar Sultan

            How can I execute a function for a huge number of users? Say 5000. In my web application there are more then 5000 users. they all get their revenue based on the business generated by them. The problem is: The revenue has to be generated daily. If I create a form with text box as user id and a button and on click of the button the function to generate the revenue execute, it is going to take forever for all the users as the query contains deleting, updating, inserting, and other tasks. So how can I create a function that executes for all the users.

            P Offline
            P Offline
            Paulo Zemek
            wrote on last edited by
            #5

            If I understood well, as soon as the next day arrives your want to execute the query for all users, right? I use some code that has this type of functionality. Effectivelly, in Global.asax I create a new thread. That thread will then, in a while(true) (yes, an infinite loop) wait for the next day. Something like: DateTime now = DateTime.Now; DateTime nextDay = now.Date.AddDays(1); TimeSpan diff = nextDay - now; Thread.Sleep(diff); And then, will execute the query for every user, sequentially. This way, you will not have problems when each user calls the method, that will only read the result. The method must only be prepared to know if the SP was run or not. You can, for example, make every user wait for the SP to run using ReaderWriterLockSlim. For example, you create a global (static) variable for the lock. public static ReaderWriterLockSlim GlobalLock = new ReaderWriterLockSlim(); When you run the SP that calculates the values, you do the pattern: GlobalLock.EnterWriteLock(); try { // execute the SP } finally { GlobalLock.ExitWriteLock(); } And, at each user read you do: GlobalLock.EnterReadLock(); try { // execute the SP } finally { GlobalLock.ExitReadLock(); } This way, the users will wait until the SP finish before reading (considering they are calling the method at midnight).

            Z 1 Reply Last reply
            0
            • P Paulo Zemek

              If I understood well, as soon as the next day arrives your want to execute the query for all users, right? I use some code that has this type of functionality. Effectivelly, in Global.asax I create a new thread. That thread will then, in a while(true) (yes, an infinite loop) wait for the next day. Something like: DateTime now = DateTime.Now; DateTime nextDay = now.Date.AddDays(1); TimeSpan diff = nextDay - now; Thread.Sleep(diff); And then, will execute the query for every user, sequentially. This way, you will not have problems when each user calls the method, that will only read the result. The method must only be prepared to know if the SP was run or not. You can, for example, make every user wait for the SP to run using ReaderWriterLockSlim. For example, you create a global (static) variable for the lock. public static ReaderWriterLockSlim GlobalLock = new ReaderWriterLockSlim(); When you run the SP that calculates the values, you do the pattern: GlobalLock.EnterWriteLock(); try { // execute the SP } finally { GlobalLock.ExitWriteLock(); } And, at each user read you do: GlobalLock.EnterReadLock(); try { // execute the SP } finally { GlobalLock.ExitReadLock(); } This way, the users will wait until the SP finish before reading (considering they are calling the method at midnight).

              Z Offline
              Z Offline
              Zafar Sultan
              wrote on last edited by
              #6

              This is almost what i was looking for. Thanks. I will try and tell you. Thanks again.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups