Solved

C# - multiple exe's for 1 project

Posted on 2013-06-01
14
488 Views
Last Modified: 2013-06-03
Hello,
I have a C# project PROJ001 which needs to call hundreds of new exe's. Each exe will perform a specific ODBC retrieval of data from a DB2 database. One exe will return an Item Description from the item master file, another exe will return a Customer name etc... However if I were to create 100 ODBC transactions then I would need to create a hundred projects (eg PROJ002 - PROJ101) as each project represents 1 exe file.

Is it possible to Created multiple exe's from 1 project (ie PROJ002 to hold 100 programs which would all have their own exe.) The reason why I am trying to keep each piece of logic as a separate exe is to facilitate changes being made to one exe which would not effect the remaining exe's and therefore eliminate having to retest everything.  However if there is a better way of doing this then I am open to advise.

regards
Pat
0
Comment
Question by:pclarke7
  • 7
  • 6
14 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39213132
You could code each functionality in a dll instead.
The solution could then have multiple projects BUT only the one exe.  Changing the dll would then be fairly simple.

ps.  Concerinng your other question.  This architecture would simplify sharing things - common code can be in yet another dll.
0
 

Author Comment

by:pclarke7
ID: 39213272
Hi Andy,
I'm not familiar with using dll. Do you have any simple examples?

Also I was looking for a solution which would give me 1 project and multiple .exe's rather than the other way around. This would allow for changes in one .exe without effecting anything else.

regards
Pat
0
 
LVL 40
ID: 39213959
A project can contain only one .exe or .dll. But you can group many projects in a solution. When you open the solution, the code from all the projects is opened. When you compile the solution, all the projects it contains are compiled.

When you are in your main project, simply do a File...Add and the existing project that you select or the new project you create will be added to the solution. You will understand as you do it.

But I question your approach. Managing the something that has hundreds of .exe would be a nightmare. Same thing for deployment and maintenance. And if your methods are such that each can be in a different exe, they are do not interact one between themselves, so the problem of having to recheck everything when you make changes in only one method does not apply.

You would be better of having a dll with a class that contains methods for each of the operations that you wanted to perform in your many exe. Deploying and updating a single dll file is a lot easier than managing hundreds of files. This is especially so if you use a deployment method such as ClickOnce, that enables the application to automatically update itself when a new version of the dll becomes available. Because it makes updates easier, you might even think of doing everything in the application.

Basically, you create a dll by creating a class libary project instead of a Windows application. You then link that dll with your application through Project...Add reference. You then use the
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39214027
You have a project - but it is actually a solution which contains one project.  Just add other projects to this solution.  To follow my suggestion you would select a library (dll) as the type of project.

Also in your other recent question you ask about sharing an instance of a class between exes.  As far as I know that is impossible.  Sharing an instance of a class object between dll's which are being instanced in one exe is actually trivial.
0
 

Author Comment

by:pclarke7
ID: 39214261
Thanks James & Andy,
I think that both of you are basically saying the same thing, which is to use a Class library and include all of my proposed exe's as methods within this class library. On the surface this would seem like a far cleaner solution. However I would be interested to get your feedback on how I might address the following issue - which was the issue that made me look at separate exe's for each operation.

Within the Pharma and medical device industries there is a huge emphasis placeed on software validation. This is partly because of FDA regulation and partly because of the potential of introducing errors into a process by deviating from validated processes. From a software perspective this means that before software can be used in a production environment ,it must be fully tested and validated against test scripts. This can be a long process. Once validated then the resulting exe is "licenced" for use.  

If at a later stage , new logic was to be added or one piece of functionality needed to be changed , then this would means that "the one and only" executable would have to be recompiled. From an audit point of view the executable has been updated and therefore all the prior validation is no longer valid. Everything would need to be revalidated because you have no way of guaranteeing that logic has not changed. If on the other hand the new logic or altered logic was held in it's own exe then only that piece of logic would need to be re-validated.

This is why I was looking at each piece of logic being an executable. Is there any way I can achieve this type of control using a DLL solution ?

regards
Pat
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39214366
I think I understand your concerns BUT all you change is the code in one dll with my suggestion and yours is changing the code in one exe.  The exe in mine has no change inside its code - in fact if done correctly would not require any recompiling of the end user exe.  (That assumes there isn't a change in the functions interface - same parameter types in the same order).

You might need to get a third party to confirm if that would be suitable, if not then your idea of multiple exe files is likely to be the 'best' way for you to go.
0
 

Author Comment

by:pclarke7
ID: 39214814
Thanks Andy,
I will certainly check out using a  dll.  One question though. Once I have all my methods, including the driver program and driver form, setup in a DLL - how do I call the DLL. I presume that I can call it from a  form application  but what is the format of the call and how do I specify the initial program to run within the dll ?

regards
Pat
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39215444
All in an exe:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Class1 c = new Class1();
            MessageBox.Show(c.Foo(2).ToString());
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show(Class1.XX(2).ToString());

        }
    }

and

    public class Class1
    {
        public int Foo(int i)
        {
            return XX(i);
        }

        static public int XX(int i)
        {
            return i * i * i;
        }
    }
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39215445
And now the dll version:
using ClassLibrary1;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Class1 c = new Class1();
            MessageBox.Show(c.Foo(2).ToString());
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show(Class1.XX(2).ToString());

        }
    }
}

and in the dll

namespace ClassLibrary1
{
    public class Class1
    {
        public int Foo(int i)
        {
            return XX(i);
        }

        static public int XX(int i)
        {
            return i * i * i;
        }
    }
}
0
 

Author Comment

by:pclarke7
ID: 39215743
Hi Andy,
thanks for that. I can see how I can call methods within the DLL by including the "Using ClassLibrary1" or whatever the namespace of the dll is called. However within my DLL is a Forms application  which is the driver program for the entire application and which gathers information from the user and places this in a global instance of a class which holds data for the application. This global class instance will in turn be utilized by all of the methods within the DLL.  So the last outstanding question is how can I make an explicit call to a Forms application (Driver program) which exists within the DLL ?

regards
Pat
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 39215905
I've added a windows form called Form1 to the classlibrary and now in the exe I can display it with code like

            ClassLibrary1.Form1 f = new ClassLibrary1.Form1();
            f.ShowDialog();

(If the name was unique one wouldn't require the ClassLibrary1.Form1 to precisely define which form is to be created, but it would still be recommended when you have large numbers of dll's / namespaces as you would be likely to have.  Helps others when reading your code at a later date)
0
 

Author Closing Comment

by:pclarke7
ID: 39216027
Thanks Andy,
for your patient advise. I'm now using the DLL approach which I believe will be far easier than going down the exe road.

regards
Pat
0
 

Author Comment

by:pclarke7
ID: 39217010
Hi Andy,
sorry to be a pain but I just realised that the calling point in my DLL has is a driver program which calls multiple Forms but is not a form itself. Therefore I cannot invoke it with ShowDialog().  How can I call a specific method within the DLL, passing parameters. The called method will in turn call a number of forms within the DLL.

regards
Pat
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39218047
The simple answer is exactly the same way you would have done in the exe file.

Look carefully at the code snippets I have shown you previously.  The code has no difference in the functionality, it is all with the namespaces to identify the location.  This is why they are dll's (dynamic link library - allthough the dynamic and link parts aren't always too relevant these days).  A library where you can store code and use in anything that has access to the library.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now