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.
Related
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 7 months ago.
Improve this question
I apologize for the multiple questions but I am having a hard time finding information on exactly what I am trying to do here.
Background:
I am working on a project that involves communicating with several server ports simultaneously that needs to somewhat scale. Some background on the project is I have a web application for users to pass commands to a console application. This console application will then send those commands to a specific port on a preexisting server through a tcp client.
My specific questions regard the console application communicating with the preexisting server.
My idea:
So my idea is to use a producer-many consumers thread scheme. I will need to be able to communicate with up to 300 different ports simultaneously and constantly through TCP connections. This console application will run as a windows service or something along those lines.
Question 1:
I am thinking of using a ConcurrentDictionary<string,ConcurrentQueue>() to track a queue of commands for every specific thread. Is there a better way to do this? I ask because I assume every thread would need access to the entire Dictionary of commands correct? Maybe this is a good approach but I have never done something like this.
Question 2:
Does spawning a single thread for each port I need to send commands to on the server make sense? The only reason I am thinking of doing this is because I will need to keep a TCP connection open for a very long time. The user can choose when to shut down the tool/connection. The only requirement really is this needs to be communicating for days at a time. The MOST I will reach is about 300 threads using this approach.
Question 3:
Obviously using an asynchronous approach is going to be necessary for this to scale well. Can anyone point me to some GOOD not out dated resources of the PROPER way to implement something like this asynchronously. I am willing to even pay for a book / online course if you have a good recommendation. The Microsoft docs are not very helpful because they do a scheme of 1 send and 1 read and then close the tcp connection.
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 6 years ago.
Improve this question
Is there a way to call a function to run on all instances of a Windows Forms application across a LAN?
I have an application which contains a dashboard of their own Joblist. I want another user on another PC to create and allocate a job to this user. Once created and saved, I would like the method GetJobs(); to refresh. I've not done anything this advanced yet, so please go easy :)
Chris Walsh has excellent advice in his comment. That said, it is possible for Windows Forms applications to communicate with each other, and the simplest method, for me anyway, is WCF, self-hosted server. Typically the server code will not be running in the UI thread -- at least I don't recommend it. In fact, all WCF is best kept running in a background thread in a Windows Forms application, to avoid blocking the UI. WCF has lots of error conditions you will need to handle.
Another thing you might want to look at is MSMQ, now called Message Queueing. It can store a queue of jobs for you, and it won't lose them if the power is lost.
I assume you have some SQL Server Express Edition installed as the database backend.
This way you can connect to the database using some authentication, and add the job's directly there.
Then on the other computer, add a refresh button or poll for changes. This has the advantage that you don't need to write a service by yourself, and jobs can be created even if the user is not there and his PC is switched off.
You need just one server which hosts the database.
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 7 years ago.
Improve this question
I have a C# ASP.NET MVC REST web service.
The webservice has two major paths/routes. One for admin, one for users.
There users are typically 1-2 admin users, and all other users are normal.
When there is a lot of traffic, the server becomes slow to respond. Currently, this means that the admin users requests are slow just like regular users.
I want the admin users requests (which use a particular route) to have top priority such that the admin requests are fast, as if there was no load on the server. A way to think about this is I want to create VIP access for admins.
One option I thought of would be just to create another server, however there are some dependencies between actions on the admin route and actions on the user route, so there would need to be additional code written to facility inter-server communication, which in turn may create a new bottleneck.
I think this can be done via code, perhaps a custom request queue which could implement priorities by creating a separate worker thread pool and give them high priority however, would this actually work - meaning a thread pool of 5 worker threads given highest priority still have priority over the main ASP.NET worker thread pool which run at default priority?
The ideal solution I am looking for a solution that requires only configuration, a small amount of code, and no new hardware. Is this possible?
OS: Windows Server 2012 R2 Datacenter (iis8).
Regarding existing bottlenecks:
This is mostly a CPU bound issue, I've looked at the performance counters while running load test. its really just an overloaded server situation, where I want to protect the performance of the admin route, and the users can temporarily suffer until the load lessens (meaning I don't want to invest in adding more capacity)
I am not familiar with prioritize Http requests on IIS server.
As you mentioned, the quickest solution is to use another server. if you use the same code base and the same database, you do not have add even a line of code.
But maybe you should investigate your problem a bit more and find your bottleneck, CPU, Memory, DB, Http requests...
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 8 years ago.
Improve this question
I'm not sure if I'm going to be able to explain it right since I'm quite sure I don't know the correct terminology involved with it, which is also why I'm having a difficult time Googling for answers.
Essentially, I'm looking to develop a program that serves as a web site. It'll run constantly (like a service) and will return HTML when an outside user sends an HTTP request thru a browser or similar to a specific port on the computer this program runs on. Basically, this program will perform various background errands throughout the day but I want to be able to expose a web front end (almost like how you would with standard WinForms, but I want to be able to access it remotely) to be able to configure it, check the status of tasks, and otherwise interact with it.
I'm looking to use .Net, but I'm open to using something more universal like Java too. Someone with experience in this area would be helpful to explain any pain points you've encountered and suggestions on how to get started.
You can do it in C# with the HttpListener class.
I published an example some time back. See A Simple Http Server.
Although you might consider whether you really want to operate at that low level. I have written a fairly complex server based on HttpListener, and if I had it to do over again I'd probably just bite the bullet and use ASP.NET. There is a bit of a learning curve, but unless your server is incredibly small and simple, an ASP.NET application will be a lot easier to write and will likely be more robust.
Here is a simple example on how to do it in C# using the HttpServer class:
http://www.codeproject.com/Articles/137979/Simple-HTTP-Server-in-C
You are doing at least 2 different things, so you should probably create a Solution in Visual Studio.NET with one project for each purpose (You can have many projects in a solution), probably with at least one Data Access project as well (of type Class Library). If the solution does things at certain times of the day, then those can be Console Applications that run through task scheduler, rather than one of more services. Services are better suited to things other than simple scheduled tasks. A Web Application project can serve up your html.
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 4 years ago.
Improve this question
I want to start a simple windows P2P instant messenger in C#, similar to AOL, ICQ, etc, but much more simple (plain text messages between 2 guys)
I don't need examples on how to do it. I can find them myself.
What I do need is a general idea of how instant messaging works (P2P, not multichat) without many technical details.
For example:
Will I need a main server to make the communication between user1 and user2 happen or user1 can send the strings directly to user2? How is this called?
If user1 is logged in, how does he know of an incoming message from another user (or the online status of their friends)? Does the chat client app check every X seconds with a main server?
Any clues that might help me clear the general data flow idea will be very much appreciated.
A flowchart may also be helpful if you find one to share.
Thanks in advance.
UPDATE (NEW QUESTION) - July 6
Let's say the user had successfully logged in, and the app needs now to get and populate the list of contacts (saved on my apache/php/mysql server).
How would you implement the data retrieval (important) and later population of the contacts list? Is WebClient.DownloadString[Async] a good approach? Is there a better way?
How often should the app check for updated list (online/offline statuses). Recommendations accepted.
How can I parse JSON data on C#.NET (Visual C# Studio 2010)
I will get JSON strings.
Thanks!
If you really want to build a p2p app, there should be no server. However, this is not straightforward.
There are lots of different approaches to creating a chat system, mostly involving servers. Research comet (a good solution if implemented properly, terrible otherwise), polling (checking every x seconds) or using sockets, however there are lots of issues to be considered - and caveats, particularly firewalls/nat routers. A socket solution could potentially be 'p2p', but the polling and comet ones are not.
For your use case, I would go with a simple socket solution (one side as server, one as client) and configure your router firewall by opening a port at the server end.
You could extend this so that both sides could be both servers (listening on a port) and clients, so you could both 'call' each other.
You will need to have a permanent ip, or use a service like dyndns to get this to work properly.
Update
Yes, DownloadString or DownloadStringAsync would be a fine method.
How often is really up to you. I assume that this is only for a few users from what you said in the question, so you don't need to worry about overloading the server. Once a minute sounds reasonable, but once a second would proabably be fine too if you feel that way inclined... Parsing JSON in .NET answers your final query.