Infinite running client [closed] - c#

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 9 years ago.
Improve this question
what I want to do is write a program that listens wcf web service frequently , say once every half-hour, and updates db according to ws result.What is the proper way of writing that kind of program.Should I create an exe and make it a windows scheduled task or write a program that has an infinite loop , maybe a thread approach.What is your opinion ?
Thank you for any help.

You probably have to create a Windows Service Application:
Microsoft Windows services, formerly known as NT services, enable you
to create long-running executable applications that run in their own
Windows sessions. These services can be automatically started when the
computer boots, can be paused and restarted, and do not show any user
interface. These features make services ideal for use on a server or
whenever you need long-running functionality that does not interfere
with other users who are working on the same computer.
In order to implement a recurring event, you need to use the Timer Class.
On a second thought, supported by these references:
windows service vs scheduled tasks
Windows Service or Scheduled Task, which one do we prefer?
//TODONT: Use a Windows Service just to run a scheduled process
a scheduled task seems also a nice solution which fits your scenario.
In terms of available .NET libraries, there is no difference between the 2 alternatives.

Related

How to start the service at background(when application is not running)? [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 3 years ago.
Improve this question
Hello i have an application working with window service and i want to start its service at background, i mean even when the application is not running the service should run at a specific time for example: start(9am) and then stop the service at (6pm).
Do you have any idea ?
Thanks in advance !
If the PC is turned off then there is no way you can start a service. You need to tun on the PC and Login fist. There are some Services that can start on boot up though, you can start an executable after boot up by adding it to HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\BootExecute. Never thought I'd see such question on StackOverflow
A service can't run if the PC is switched off. I assume that you want the software to run even if the user is not logged in.
If you want to run software without logging in, you won't have a user interface. Windows Programs without user interface are called services, and they can be started manually, or automatically whenever the computer is switched on.
As you have a windows forms application, you'll have to separate it into two applications: one with the user interface parts, and one with the parts that you want to run as soon as the computer is switched on. The latter part has to be put in the windows service software.
Whenever an operator logs in, he starts the windows forms program that holds the user interface parts. This program communicates with the already windows service.
There are numerous examples, also here on stackoverflow that will help you how to create and start a windows service and how to communicate with a running service.
That's a server not a service, NOTHING runs on a personal computer when it is turned off, even when servers shutdown, nothing runs on them too.

Is is possible to start/stop windows service via some other windows service or same windows service? [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 3 years ago.
Improve this question
Is is possible to start/stop windows service via some other windows service or same windows service? I have windows service running on multiple PCs, As I want to update that service whenever any version change, So I want to handle windows service via code with some other or same windows service?
Typically upgrading a service requires replacing its exe and supporting DLLs but no additional registry changes unless something about the service registration is to be altered (startup type for example).
There's no reason why your service cannot launch a small updater program that will stop, replace and restart the service but generally you won't succeed in getting any running program to replace itself because the exe tends to end up locked/in use while it is running. The updater program doesn't need to be registered as a service
Be mindful that you might have to launch the updater using credentials that have permission to stop/restart a service and alter the program files subfolders; services should generally run using the lowest (least permission) possible and running an updater app using the same credentials might not give high enough privileges to replace the exe
See How can a program delete its own executable for more ideas on self replacing programs

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.

Alternative way for Background Process [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 6 years ago.
Improve this question
I've created a simple application in C# which purpose is to have a Windows Service running on Background in the whole time the computer is alive and which I know is a non-GUI process.
I want the Service to execute some command like, programmatically lock the computer, send data to one of my Windows Form Application, show Windows Form Application etc. which will not work because it is Windows Service. I found it really hard for me to work with this.
Now, my question is, is there any alternative way for what I want to achieve?
I mean other solution for running background process in the whole time and do the GUI job?
I am really out of ideas, anyone can suggest/help will be very appreciated!
You can always write a winforms application that will run a background thread listening for commands and executing tasks. Then all you need to do is register this executable to be started when a session is started. The application could be minimized to the tray so that the user could still manipulate it.

How to call functions on other computers? [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 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.

Categories