Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 16th, 2008, 12:11 PM
Registered User
 
Join Date: Apr 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default schedule C-Sharp process

Greetings to everyone.

I have a asp.net web application written in C#. There are several areas of the application that I wish to have in a stand alone process that will be run with a scheduler.

I know how to create a cron job with php/mysql, is it possible to do this with C# code? Write a C-Sharp script that is called and all it does is runs, similar to using php.exe to run a php file by specifying the file path. No output is required as it is DB updating and moving files form one folder to another every minute.

Must I create a separate application and create a EXE from it using my working C# code to run in this fashion?

Thanks to anyone with some insight.

 
Old April 16th, 2008, 01:19 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

There is no such thing as a C# "script". C# must be compiled into an executable assembly whether it's a DLL or a EXE by itself.

Typically the requirement you describe can be accomplished by creating a command line executable that performs the desired task, and that exe is set up in the windows scheduler. I tend to stay away from the windows scheduler as it has poor tracking capabilities and I've found it fails to regularly for my liking.

Given that you are doing DB updating, is there a reason it needs to be in C#? Can the DB updates be handled by SQL code? If so, then you can do it all with a SQL job (assuming the DB system you are using supports such jobs).

-Peter
peterlanoie.blog
 
Old April 16th, 2008, 01:55 PM
Registered User
 
Join Date: Apr 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The process is as follows...

VoxWare is being used by pickers on the warehouse floor.

If they are in need of X amount of a product for an order they voice in they are short.

The VoxWare will fire off a fixed length flat file to a special directory. These files end in ".REP".

I have the code to slurp up any files that end in .REP and read in the data, update it in the DB for the replenish guys and than transfer the now defunct file to the archives.

I want to make this file so it can be run every minute and not be a page that has to be surfed to in a browser (how it works right now).

There are other processes that must be done in a similar fashion. I have test written a few exe files and made sure they will work (as in they compile and run correctly), but was looking for a way to schedule them to run similar to how Cron jobs run.

Cron simply calls the php file through php.exe. There fore there are no requirements to "surf" to the appropriate php page and there ins't this annoying command window that pops open for a second before self closing (I actually can let that be, just find it vulgar).

So I have an idea on how to accomplish this, but was hoping for some insight into how to cleanly perform this. I have a exe file that will work but when run it pops up an ugly blank command window than closes every time it is run. No one will normally be on this machine that will run the code, I just hate such vulgar processes and was hoping for a clean way.

Thanks.

 
Old April 16th, 2008, 02:02 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmm. Doesn't seem like this is well suited as an ASP.NET application at all (I bring up ASP.NET here since you are using PHP in your example, although it appears as though you are writing C# Windows apps). Have you considered writing a Windows Service that implements FileSystemWatcher? I think this may be your best bet.

Personally, within my company, we wrote a service that works similar to this where something is done on a website and some value is then wrote to a database. Next, at set intervals, this service executes, reads the new information from the database and then completes the necessary action.

I think something like this is better suited for what you are trying to do but and it solves the problem of not spawing a command window. However, if you don't wish to use a windows service, this SERP has plenty of links on how to schedule tasks: http://www.google.com/search?source=...schedule+tasks

Finally, if you want to supress the Console window completely you are probably going to have use P/Invoke to do this. This SERP should help you: http://www.google.com/search?hl=en&r...command+window

-Doug

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old April 16th, 2008, 03:45 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I'd go with just what Doug said. Windows service with a file system watcher. It will eliminate the annoying pop up command window and will be more efficient because it will remain idle until files appear.

-Peter
peterlanoie.blog
 
Old April 18th, 2008, 10:51 AM
Registered User
 
Join Date: Apr 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, question.

Can I place my code in the Elapsed event of Timer or must it always call to some outside process like so many examples show?

 
Old April 18th, 2008, 11:15 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You can certainly put any code in the timer event handlers. However, generally you'd just call out to some code because you'll probably want to be able to test the code from a process that doesn't rely on the timer or even the process that hosts the timer (perhaps a windows service).

-Peter
peterlanoie.blog
 
Old April 18th, 2008, 12:41 PM
Registered User
 
Join Date: Apr 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So your saying to write the windows service that has a timer (and of course install it), so that on every 60 seconds (or 60,000 miliseconds) have the Elapse time event handler call a .exe that is a compiled version of my code that will suck in files and process the data, than move those files to the archives?


That is the direction I am going. Is this what your thinking is?


As to the FileSystemWatcher class, nice features, but I have found it to be redundant as 99% of its features will not be used, so I will stick with the just go through the directory on every process call whether there is going to be files or not.

 
Old April 18th, 2008, 12:47 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Just a quick note. Take in mind that if you do something like you are planning, you will have to stop the timer and reenable it after the .exe has finished working. Why? Because you can have a problem somewhere that will slow the .exe and make it last more than a minute, and if you launch the .exe again, you will have 2 programs compiting for the same resources and it can lead to "POTENTIALS" problems (maybe not, but who knows?).

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old April 18th, 2008, 10:21 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Derf,

I'm not sure why you wouldn't use a class that will do just what you need. Yes, the FileSystemWatcher class may contain many features that you aren't going to use, but that could be said for practically every class in the framework. Why over complicate your program with your own concoction of logic when the framework provides tested behavior that is exactly what you need? I would argue that while the built in class may contain features that you won't use, whatever overhead you feel is being taken up by that is far outweighed by the inefficiency of an app that just polls the disk for changes every minute.

Also, I wouldn't recommend simply having a server call another executable. Put your primary logic in a class library assembly then you can build a standard command line app for testing and the service for the live deployment. You should be able to put all the monitoring functionality into the main logic assembly. Then the command line app and the windows service will just be execution stubs for the main logic. This is the model I've seen used and one I've implemented myself with success. Having a service exe call another exe will prove quit difficult to debug once the app is running "in the wild".

The other thing I'd recommend strongly is that you implement very strong logging in the app. I've used log4net with great success. It allows for good control over the level and output options of logging, of particular importance once you start getting into service apps.

-Peter
peterlanoie.blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
process.startinfo opens new instance of process Anypond General .NET 0 August 28th, 2008 05:35 AM
About schedule Task brijit VB.NET 2002/2003 Basics 1 November 8th, 2006 01:21 PM
HOW TO EDIT THE MAC WITH C SHARP? ÄÏÔÚÄÏ·½ C# 0 June 23rd, 2006 02:38 AM
schedule in calender rita General .NET 0 June 19th, 2004 03:37 PM
Schedule a sychronisation ppenn Access 1 November 12th, 2003 09:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.