Run code after form load periodically - c#

I am developing a desktop window application. After form load, get some data from running machine and saved it to the ftp server in csv file and it shows that test completed. I want to run the same code which takes values and store on the sever after every one hour. How can i do it?
Console application and window service is not feasible solution because I have to show the form to the user etc.

Use one of the timer classes that come with the BCL.
See Comparing the Timer Classes in the .NET Framework Class Library on MSDN.
Essentially you setup a timer with an interval (how often to fire, in your case every hour) and with a method to execute when it fires.

Related

how to set a program to run automatically once a day in c#

I am a newbie to programming So I need lot of support from my friends I am creating a windows forms application and I need that program to run automatically once a day and need to close itself after 2 minutes of the execution how to do it....
I need that program to run automatically once a day
You can use Windows Task Scheduler.
need to close itself after 2 minutes of the execution
You can implement in your application using many different approaches.
For instance, since you write WinForms applications, you can use Timer.
I would like to take the below approach.
Write console application. and add appropriate log message so that you can understand how it goes. if the application need any parameter then pass it from command line or put in a file so that the app can read the file and run automatically.
Add the app to Windows schedule task and monitor log regularly.
if the input parameter changes everyday then just update the input file when necessary.
Hope it will give you a idea.
Thanks.
Ruhul

Passing data to Windows Service

I have two application modes one is Console application and Windows Service both suppose to do the same job console will take user inputs and base on user inputs it will proceed with intended task and user inputs will be saved as user settings.
I need Windows service to use the same settings and do the same task in background with scheduling. Currently I'm facing the problem where user settings are not available when reading from Windows Service.
You can save the user settings (at time of running console app) in an XML file and read that file in your windows service and work accordingly
There are 3 possible routes that I can think of to deal with this issue (I will update this later today with more detail when I have more time).
First, combine the applications into a single Program. Modify Program.cs so that you can pass in an argument telling it to run as a Console application or Service. This method helps you to make sure that you are doing the same thing in both uses, without repeating a lot of code.
Second, share the settings file between both projects. This seems to be the basic question you are asking. I'll elaborate on this when I have more time this evening.
Third, ask if you really need the service for what you are trying to do. If the service is only being run at certain times of the day, it might be better to instead focus on allowing the Console application to also run without input, as a Scheduled task.

how to make windows startup project with many methods running at the same time in the background

I have explained my project below and asked some questions with "My Question-" tag.
I have working on a project. At the time of windows logon page if I enter a wrong password my cam should take the picture, If I open regedit my system should take a screen shot and save these images in C:\Windows\system32\new folder (I tried a lot making this work with the help of manifest files but failed everytime) and emails it whenever finds an internet connection
I have a form based app because I didn't find any other way to capture image from webcam directly but taking input from pictureBox1.Image.
My cam, screenshot,email (didn't find a way to autocheck if has internet connection available or not) and 3 events checker for "firewall enable/disable, windows logon failure , regedit event called" are done and they are working good.
What I need to do is to assemble these codes to work as an app and running in the background continuously from the time of windows startup to shutdown
To validate positive events I need to make a desktop based db ("My Question"- still figuring out either to choose sql or localdatabase in c#. Please also tell me a suitable solution.I have to delete all the entries from the db once a day is over). The db would contain the following columns (event id, event name, event timestamp).
I want my app to check if this very event exists in the db then it should ignore the event generated on windows event log else it should make a new row with the db columns and it should do the following actions based on the event like taking webcam pic or screenshot.
"My Question"- I want my app to be live at the time of windows logon page. A lot of programs start later when you are authenticated but I need my program to be live at the time of logon page. Do I have to make 1 or many services? or multi-threaded? because in the typical form based app you can only call one function at a time and wait for it to return something or perform some task/action and then you call the second third whatever.
"My Question"- Do I need to use the backgroundworker in c#
Please help!
You have a lot of things going on here for one question.
You can put all your code in a background service that gets started at boot time. There is a walkthrough here to show you how to do that (along with a million other sites).
Addressing some of the other issues you listed:
Google is your friend...
Webcam - Found a quick reference here and here
File Modification - Another SO thread here
SQL vs. Other Database - Not sure you need anything elaborate here, probably something you can put together pretty quickly. Another SO thread addressing that here
Good Luck!

Webbrowser control in C# weird behavior

I'm finishing (QA testing) a web parser built in C# that is parsing specific data from a
web site that is being load to a webbrowser control in a WFA (Windows Form Application) program.
The weird behavior is when I'm killing the internet connection... Actually the program is designed to navigate recursively in the site and each step its waiting for a WebBrowserDocumentCompletedEventHandler to be triggered. Beside that there is a Form timer set,
and if the handler is not triggered in a specific interval then its reloading the entire procedure.
Everything is working good even if I manually avoid the handler from triggering - As I said the timer kicks in and restart the operation successfully and retrying another value successfully.
When shutting the internet connection manually while the procedure is running, I can see the page is getting the internet explorer message: "This page can't be displayed"
(For some reason the DocumentComplete... is not triggered).
Then immediately reconnecting the internet and waiting for the timer to kick in - As expected it fires the reload function but this time everything is going wild!! the functions are being fired not in the correct order and it seems like there is 100 threads that are running at the same time - a total chaos.
I know that its not easy to answer this question without experiencing that and seeing the code
But if I copy the entire code it will be just too long using 5 different classes and I really can't see where is the problem...
I'll try to simplify the question:
why when connection lost the documentcomplete handler don't fires?
Does anyone has experienced an application going wild only after webbrowser control losses connection?
Thanks

launch winforms app on schedule - provided conditions are met?

I am designing an app which basically is going to check for new data, my initial thought for this is to use a windows service. If i get any new data i need to display a winforms app which i'll populate with this data so that the user can acknowledge it.
I know there are restrictions running UI apps from a service so i'm just wondering what others believe is the best approach for both. Also i need to run this on XP
The timer that gets the data
how to launch the WinForms App
As im writing this i've also been toying with the idea of using a console app but nothing seems to be fitting together in terms of functionality.
You can use a regular Winforms app. As soon as the application loads, hide the entry form from within the Form_Load method, this will keep the form hidden from the user. Keep a timer on the entry form that frequently checks for relevant data and pops up windows as and when required.

Categories

Resources