• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 468
  • Last Modified:

C# Console application

Hi.

I am writing a console application that I would like to use to call a procedure from another program, instead of rewriting the code again.  I have added the program to my "References" file, but I am unsure of how to call the procedure from the other program.  Can anyone give me some samples on how to do this?  I am using Visual Studio 2008
0
Jasmin01
Asked:
Jasmin01
2 Solutions
 
Kalpesh ChhatralaSoftware ConsultantCommented:
0
 
käµfm³d 👽Commented:
So as you seem to be aware, a .NET executable can be referenced the same way a .NET DLL can be. The not-so-obvious trick to this (for those new to it) is that you don't enter the DLL the same way the system does when it wants to execute the application. Once you reference a .NET executable, you are effectively treating it as a library (DLL). How do you execute anything found within a library? You create instances of the classes or invoke the static methods found within the library.

All .NET executable have a class wrapping the Main method. This class is called "Program", by default. If there are any non-static methods found within Program, then you can create an instance of Program in order to execute any of those methods. If your intent is to call Main, then you simply preface the call to the static Main with the name of the class:  Program.Main(new string[] { "arg1", "arg2" });.

You would work with any other classes defined within the executable in a similar fashion.
0
 
Jasmin01Author Commented:
I have created the console application and I have referenced the exe application, like the code below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AppMailer;

namespace Mailer
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}

I have to call the function found in my form1.vb file, but I don't know how to do this.  Can you help?
0
 
Kalpesh ChhatralaSoftware ConsultantCommented:
if form1.vb Class name is Form1 then you can call like below

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AppMailer;

namespace Mailer
{
    class Program
    {
        static void Main(string[] args)
        {
               Form1 oForm = new Form1();
               oForm.Show();
        }
    }
}
0
 
Julian HansenCommented:
@kaufmed - very nice explanation.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now