?
Solved

C# How to reference an application as a dll to be used in a console application

Posted on 2012-09-17
14
Medium Priority
?
309 Views
Last Modified: 2012-09-25
Hi.  

I have an application that we use to send reports manually on a daily basis.  I would like to automate this process by using a console application to call the application so that I may run this as a scheduled task without any interaction from anyone.  I only need to call some functions from the main application, but I do not know how to create a dll from the application.
0
Comment
Question by:Jasmin01
  • 5
  • 4
  • 3
  • +2
14 Comments
 
LVL 5

Expert Comment

by:sameer_goyal
ID: 38404876
Instead of doing that, you can create a windows service to automate the process for you.
Creating a dll and then using that in the tash scheduler, I don't think its such a good idea and moreover, I am not sure if .NEt would allow that.

Windows Service is a much cleaner way to do it.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 38404885
>>but I do not know how to create a dll from the application.

Actually I think you should create a new project (library) and put the common code from the two applications into that.  Then each application can call functions from the dll.  The reason being is that an application is not the same as a dll - dll's don't have a main procedure wheras an app needs one to start the UI for example.


(Unless you mean starting the original application and passing messages to it - as if the user clicked a button / selected a menu).
0
 

Author Comment

by:Jasmin01
ID: 38404887
Can you give me a link to a tutorial or somewhere that I can get some help with creating the Windows Service?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 5

Expert Comment

by:sameer_goyal
ID: 38404889
Here it is

http://msdn.microsoft.com/en-us/library/aa984464(v=vs.71).aspx

pls let me know if this help or you need some assistance
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 38404901
Further to my first comment.
Do you know of command line parameters?
You might not even need to code a second console app or a windows service.  Just start your current app from the task scheduler and pass parameters via the command line.

eg.
foo  (start your app with the normal UI)
foo - h -x"Instructions.txt"  (YOU NEED TO CODE IT, start your app hidden and tell it to process a file)
0
 

Author Comment

by:Jasmin01
ID: 38404914
I dont know about command line parameters.  Are there any tutorials on how to code the command line instructions?
0
 
LVL 5

Expert Comment

by:sameer_goyal
ID: 38404916
Hi jasmin01,

What is your current application like? Is it a Windows Application or a console application?
Can you provide an overview of how does it work?

Even better, if you provide a snapshot of the method/function that basically generates the reports for you, I may be able to provide a starting point on the command line parameters
0
 

Author Comment

by:Jasmin01
ID: 38404928
Hi Sameer,

It is a Windows application that has 4 different users.  It was originally deigned for the 4 users to log in every morning and run the reports for themselves, but now they require that I have to log on as all 4 users, (one at a time) and run the application.  Once you log on, you have to select the type of report, (daily/weekly or monthly).  Once the type is selected, eg. Daily, a list of reports is populated on a gridview.  You then right click on each of them and select, "Run".  The reports are then sent to the appropriate email address listed in the system.
0
 
LVL 5

Expert Comment

by:sameer_goyal
ID: 38404943
Ok

So I assume you have a method in there which would take 'Report Frequency' or 'Period' as the parameter and fetch the data according to the business logic and displays that on the gridview.

Is that correct?

And now you want to automate this so that everyday, daily reports are generated and emailed to the appropriate people.

If you want to use the command line parameters, or you prefer using the windows service way, both will require you to change the existing application slightly.

For command line parameters, you will probably have to make modifications to make your application have a single entry point and that method should take command line arguments.

I believe, creating a windows service would be easier and quick.
0
 

Author Comment

by:Jasmin01
ID: 38404958
Yes, there is a report frequency field in the table, with either D,W, or M in that field.

I would prefer to create a Windows service.  I can tweak the main application if need be.
0
 
LVL 5

Accepted Solution

by:
sameer_goyal earned 1400 total points
ID: 38404976
great. so that link that I shared earlier should help you.

here's another one

http://blog.themobilebrand.com/technology/tutorial-building-a-windows-service-application/
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 600 total points
ID: 38404979
Run the main application itself passing it a parameter saying it is running in batch. Check http://emoreau.com/Entries/Articles/2008/11/Passing-arguments-to-an-application-startup.aspx
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 38405128
The following is a Microsoft tutorial about how to use command line parameters.

http://msdn.microsoft.com/en-us/library/aa288457%28v=VS.71%29.aspx



ps.  I use a similar technique to run an app (not a service) daily via the task scheduler on a server.  It works (and has done so for some years) reliably.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38406444
You could add the application as a reference* within the Console application. You would then just need to create instances of the appropriate classes and execute the required methods.

* - This assumes the application in question is a .NET application.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question