Function for n number of users.
-
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.
-
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.
you can pass the where as parameter if no user (specific user ) pass ""(nothing)
-
you can pass the where as parameter if no user (specific user ) pass ""(nothing)
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.
-
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.
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
-
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.
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).
-
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).
This is almost what i was looking for. Thanks. I will try and tell you. Thanks again.