How can I create a recurrent tasks in .Net [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 months ago.
Improve this question
For one of my project, I need to create a task that updates the status of cars when they are late.
They are considered late when they exceed their schedule time.
So, I would like to know what is the best solution to do this.
Should I create a job that run every minute ? Or are there better solution that are less resources expensive ?

Considering the question, one of the solutions could be to use a scheduler like Quartz.net (https://www.quartz-scheduler.net/).
You did not present a lot of detail on the problem itself, so i am assuming that you are doing something like lending the car for someone and they have a time limit.
Since that information was not provided, there are a lot of scenarios. Do you really need a scheduler? Do you want to know if they are late when they are delivered/arrive? If so, you probably just need to calculate whenever the delivery/action you are expecting happens.
But, if you really need a scheduler to trigger something, you can use a scheduler.
Quartz.net can be in memory (good for POC purposes: https://www.quartz-scheduler.net/documentation/quartz-1.x/tutorial/job-stores.html#ramjobstore), but also in database (so you can share with multiple instances of the same service https://www.quartz-scheduler.net/documentation/quartz-1.x/tutorial/job-stores.html#ado-net-job-store-adojobstore).
You can simply have a job that has arguments (such as the car id), and then reuse the same code. The jobs can be scheduled in several ways, simply datetime (https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/simpletriggers.html#simple-triggers), or even be recurrent with cron expressions (https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/crontriggers.html#example-cron-expressions).
There are other schedulers available, but Quartz.Net was the one i already used in several scenarios, both professionally and personally

Related

Which is better, a scheduled task or windows service? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I have created a console program that transfers data from a database to a server. This program must run every day at a certain time. At first I thought of a scheduled task but the problem is that it depends on a user being logged in. However, as it is rather tricky and the service has to run every day, I came to the Windows service through my research.
However, most of the information comes from 2009 and 2010 and may already be outdated? I also found a guide explaining how to create a scheduled service:
https://www.aspsnippets.com/Articles/Simple-Windows-Service-that-runs-periodically-and-once-a-day-at-specific-time-using-C-and-VBNet.aspx
Is that still best practice to do it that way? What would you recommend?
Your first thought was right, use a scheduled task and select the 'Run whether user is logged on or not'.
If you use a Windows Service you have to code the trigger yourself which could be fraught with errors.
If you'd like something more 'enterprise' I'd suggest looking at Quartz.NET. It's an open source scheduling library, although it's probably overkill for what you're trying to achieve.

Need to create a queue to run process for one person at a time [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I lack the knowledge to even know where to start researching this topic (such as keywords to use) so I'm hoping somebody can help point me in the right direction.
I have an .NET MVC application. In this application, the user uploads a zip file with a data layer and that data layer is used as input in a python script the application calls. Due to the nature of the database cursors (it's an ArcGIS Enterprise geodatabase if anyone is familiar) only one person can run the python script at a time as the cursors make exclusive locks on the database (there is no way around this). In the extremely rare chance that two people are trying to use this web application at the same time, I need to put the people in a queue so the python script completes for the first person and then starts on the next person's dataset. Where do I get started with this, or what words can you give me to start formulating some search queries on this topic?
Maybe there are more technology specific solutions will come, but from my first view, you can use priority queue style processing.
It can be as simple as creating a table and enqueue (insert) new requests over there and process as it comes (dequeue). Or, use higher level framework like RabbitMQ
So, every time when new zip file comes,
Upload in repository
Insert new record in the queue
Get first item from queue
Process
If second person uploads new file, you will check queue table, there will be flag last item is getting processed, then you can let client know, script is queued and will be processed.
Obviously it will be worth to generate unique id of client, then you will not mix priorities and scripts, if there are multiple uploads at the same time.

How the controllers work in asp.net mvc? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I need a counter in the server which holds the number of http requests it received.As each server can handle multiple requests asynchronously (lets say the same controller is being called by every user) at a specific point of time, where can I place the counter so that it can be shared between every request made.
Yes, the controller is instantiated and disposed with each request. Yes, each request gets it own thread, though that thread may be exchanged (in the case of async work) or may serve multiple requests over its lifetime.
Parallelism is a complex topic and based on numerous different factors at any give time. Simplistically though, yes, threads will run in parallel. However, they do not share resources between each other (for the most part). Ultimately, there is some resource-sharing via the parent process, but for practical application, you should consider them idempotent.
Based on all that and your final question, if you have designs on trying to implement a counter in your code, don't. It won't work and never will. Even if you can somewhat coordinate some sort of process-bound thread-safe counter, it won't work with workers and it will be killed every time the App Pool recycles, crashes or otherwise restarts for any reason.
A counter should be implemented in a database or other persistent data store. Full-stop. Even then, you'll need to be extremely careful with concurrency, and unless you devote a ton of time to excluding bots, repeat page loads by the same users, etc., your count will be off no matter what.

MVC5 delayed event [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
General question
From my backend code I want to trigger events that will wait somewhere around 30 minutes and then run a bit of code.
Given that its a bad idea to spawn threads or tasks in MVC (as the pool can be killed and you don't really know if things are going to work or not). What is the best way to do this?
My options as I see them are:
Create a thread or task from the code.. bad idea as mentioned above.
Create a scheduled task (batch/powershell) on the server that calls a service every 30 minutes
that does the emailing as needed. This to me is messy as I now depend on this task working
Create an SSIS package on the SQL server to do pretty much the same as the scheduled task, but perhaps more reliably. Probably the most dependable solution, but also the most pain in the ### one..
What would you guys do?
Real world example
User "A" writes a comment on the website. User "B" and "C" both comment this post within 5 minutes of each other. I want to send an email to User "A" about the new comments from "B" and "C", but I don't want him to get 1 email for every commment.. There could be hundreds and noone wants 100 emails about 1 comment each.
So in my case I want to trigger an even that waits 30 minutes and then groups all new comments into one notification email.
There is no correct answer to this question, it is primarily opinion-based.
Personally I like #2, it doesn't seem messy to me. You could do something like a WorkerRole or WebJob. Cloud computing is as much about timed events as web requests (ok maybe not as much, but it still plays a meaningful role in many applications).
I also like #2 because it seems more unit testable to me, but maybe that's because I don't know how to write unit tests against an SSIS package.
Web server is not the right tool to for scheduled tasks. The server goes into sleep after a period of time if there is no request coming. I know there are some hacks you can do to make it work..but hacks are hacks, I always prefer to do thing the right way. To do so you would want to write some c# application and use windows service to accomplish the job, or SQL Server agent.
In my opinion there's also another option. You could expose some app on the server which has web interface so you can enqueue some task. Then internal logic of that app could send your e-mails or do anything you want. It won't be the MVC web application but some service, so it won't be at risk to be killed by application pool recycling or anything else.

Multithreading advice on approach needed [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have been told to make a process that insert data for clients using multithreading.
Need to update a client database in a short period of time.There is an application that does the job but it's single threaded.Need to make it multithread.
The idea being is to insert data in batches using the existing application
EG
Process 50000 records
assign 5000 record to each thread
The idea is to fire 10-20 threads and even multiple instance of the same application to do the job.
Any ideas,suggestions examples how to approach this.
It's .net 2.0 unfortunately.
Are there any good example how to do it that you have come across,EG ThreadPool etc.
Reading on multithreading in the meantime
I'll bet dollars to donuts the problem is that the existing code just uses an absurdly inefficient algorithm. Making it multi-threaded won't help unless you fix the algorithm too. And if you fix the algorithm, it likely will not need to be multi-threaded. This doesn't sound like the type of problem that typically benefits from multi-threading itself.
The only possible scenario I could see where this matters is if latency to the database is an issue. But if it's on the same LAN or in the same datacenter, that won't be an issue.

Categories