Run process continuously pass objects with current time to event?


Run process continuously pass objects with current time to event?



I have a list of transactions in a list with each transaction having a specific date/time



I need to implement something that is always running then checks my list and fires off a method given each transaction found for the current time



What is the best approach for this?



For example



Transaction 1 11:22:11
Transaction 2 11:22:55



At 11:22:11 I need to fire off a method giving the method Transaction 1
At 11:22:55 I need to fire off a method giving the method Transaction 2



I have seen people mention quartz but my requirement doesnt really fit into a scheduler/job scenario and I need this to be running within my application



I am using C#



Paul





What if your program IS NOT running at the given time?
– nabuchodonossor
Jun 29 at 11:11





Are you sure this should be done within your app? Think about task scheduler or writing a service
– nabuchodonossor
Jun 29 at 11:12





I'm not sure about the thread/event approach as that would create loads of threads The point is to have one thread whose job it is to repeatedly check the time and fire the needed requests. You don't need to create many threads.
– Flater
Jun 29 at 11:14



I'm not sure about the thread/event approach as that would create loads of threads





What is the goal of replaying the events? I'd think that clicking buttons yourself would be considerably easier and functionally equivalent for your intentions. Why does it need to be scheduled? Are you trying to reproduce race conditions?
– Flater
Jun 29 at 11:16






I am trying to replay actions that occurred yesterday in real time there can be a lot of transactions so clicking buttons is def not an option. If I go down the thread route do I just have a while loop that never ends that constantly checks the time?
– Paul
Jun 29 at 11:18




1 Answer
1



You can create Extension Method for List and then call your method from extension method.



That way you'll have the current object of the transaction and at the time of adding it.


public static class MyExtensions
{
public static void AddWithFire<T>(this List<T> list, T item)
{
list.Add(item);
// Add Your method call with item object
// YourMethod(item);
}
}



Update: Let say you want to play with any property of your object


public static class MyExtensions
{
public static void AddWithFire<T>(this List<T> list, T item)
{
list.Add(item);

if(item is Transaction)
{
// Call Your method that takes DateTime
YourMethod(((Transaction)item).TransactionDate);
}
}
}

public class Transaction
{
public DateTime TransactionDate {get; set;}
}





My transaction has a property inside TransactionDateTime not too sure how this approach fits in?
– Paul
Jun 29 at 11:19





Paul Check my updated answer that'll help you.
– Mihir Dave
Jun 29 at 11:25





Thanks my task here is more to only call my method at the specific time for the object
– Paul
Jun 29 at 11:27





Yeah @Paul the way I added a check for date time any way you like, similarily I have added for transaction object.
– Mihir Dave
Jun 29 at 11:30





My list already has transactions in it. The caller will be creating this list and i need something that looks at this list all the time, running the method for each transaction 1 by 1 that has the current date/time
– Paul
Jun 29 at 11:33






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Possible Unhandled Promise Rejection (id: 0): ReferenceError: user is not defined ReferenceError: user is not defined