By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,975 Members | 1,131 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,975 IT Pros & Developers. It's quick & easy.

Is it possible to have two Main() in one solution?

P: n/a
ano
Hi,

I'm a C# newbie. My application (Solution) contains two Windows application
projects. They create their own ".exe" output that means there are 2 Main()
methods in one solution.

Is is possible to do this? If it's possible, how Project A (A.exe) calls
Project B to start (B.exe) application?

I can't add a project reference in Project A to call Project B because
Project B doesn't contains .dll.

Thanks,
Mar 30 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a
You can use the Process.Start method to run B.exe from A.exe

http://msdn.microsoft.com/library/de...tarttopic3.asp
ano wrote:
Hi,

I'm a C# newbie. My application (Solution) contains two Windows application
projects. They create their own ".exe" output that means there are 2 Main()
methods in one solution.

Is is possible to do this? If it's possible, how Project A (A.exe) calls
Project B to start (B.exe) application?

I can't add a project reference in Project A to call Project B because
Project B doesn't contains .dll.

Thanks,


Mar 30 '06 #2

P: n/a
ano
Sorry I didn't mean to run B.exe by using Process.Start.
I mean how to call Project B: Application.Run() in Project A.

thanks.

"ad*********@gmail.com" wrote:
You can use the Process.Start method to run B.exe from A.exe

http://msdn.microsoft.com/library/de...tarttopic3.asp
ano wrote:
Hi,

I'm a C# newbie. My application (Solution) contains two Windows application
projects. They create their own ".exe" output that means there are 2 Main()
methods in one solution.

Is is possible to do this? If it's possible, how Project A (A.exe) calls
Project B to start (B.exe) application?

I can't add a project reference in Project A to call Project B because
Project B doesn't contains .dll.

Thanks,


Mar 30 '06 #3

P: n/a
Hi,

You cannot.

You have a solution with two separate executables. They live endependently
one of the other. If you want to start running an instance of one from the
other you have to use Process.Start.
Otherwise, why you want to run B.App_Run ?
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"ano" <an*@discussions.microsoft.com> wrote in message
news:BE**********************************@microsof t.com...
Sorry I didn't mean to run B.exe by using Process.Start.
I mean how to call Project B: Application.Run() in Project A.

thanks.

"ad*********@gmail.com" wrote:
You can use the Process.Start method to run B.exe from A.exe

http://msdn.microsoft.com/library/de...tarttopic3.asp
ano wrote:
> Hi,
>
> I'm a C# newbie. My application (Solution) contains two Windows
> application
> projects. They create their own ".exe" output that means there are 2
> Main()
> methods in one solution.
>
> Is is possible to do this? If it's possible, how Project A (A.exe)
> calls
> Project B to start (B.exe) application?
>
> I can't add a project reference in Project A to call Project B because
> Project B doesn't contains .dll.
>
> Thanks,


Mar 30 '06 #4

P: n/a
> I'm a C# newbie. My application (Solution) contains two Windows application
projects. They create their own ".exe" output that means there are 2 Main()
methods in one solution.
Is is possible to do this?
Of course, that's the point of having "solutions"; grouping several EXEs and
DLLs together and managing their relationships.
If it's possible, how Project A (A.exe) calls
Project B to start (B.exe) application?
I don't see why you would want to, but see below if you do. What is it
you're trying to achieve? You probably don't even want to have two EXEs, if
the goal is perhaps A has a main form and B has a dialog that A needs to
pop-up, then B should be in a DLL rather than an EXE (it can still be its own
project if you like, I have some dialogs that I use with several forms) form
A would then instantiate and show it, there is no need to call a Main to show
the dialog.
I can't add a project reference in Project A to call Project B because
Project B doesn't contains .dll.


Of course you can, an EXE is an assembly.

-----

I did it with console EXEs, but it ought to work with WinForms as well.

1) Make sure the class for B is public and its Main is public
2) Add a reference to project B to project A
3) In A, use: classB.Main ( args ) ;
Mar 30 '06 #5

P: n/a
ano
Thanks PIEBALD.

Now I can call B.Main(). But I need to change the output type to Class
Library otherwise I can't add a reference.

"PIEBALD" wrote:
I'm a C# newbie. My application (Solution) contains two Windows application
projects. They create their own ".exe" output that means there are 2 Main()
methods in one solution.
Is is possible to do this?


Of course, that's the point of having "solutions"; grouping several EXEs and
DLLs together and managing their relationships.
If it's possible, how Project A (A.exe) calls
Project B to start (B.exe) application?


I don't see why you would want to, but see below if you do. What is it
you're trying to achieve? You probably don't even want to have two EXEs, if
the goal is perhaps A has a main form and B has a dialog that A needs to
pop-up, then B should be in a DLL rather than an EXE (it can still be its own
project if you like, I have some dialogs that I use with several forms) form
A would then instantiate and show it, there is no need to call a Main to show
the dialog.
I can't add a project reference in Project A to call Project B because
Project B doesn't contains .dll.


Of course you can, an EXE is an assembly.

-----

I did it with console EXEs, but it ought to work with WinForms as well.

1) Make sure the class for B is public and its Main is public
2) Add a reference to project B to project A
3) In A, use: classB.Main ( args ) ;

Mar 30 '06 #6

P: n/a
> Now I can call B.Main(). But I need to change the output type to Class
Library otherwise I can't add a reference.


No you don't. You can add a reference to an assembly that's in an EXE.
May 15 '06 #7

P: n/a
>> No you don't. You can add a reference to an assembly that's in an EXE.

I believe what he is saying is that the Right-Click "Add reference"
feature on Visual Studio will refuse to add the reference until the
assembly has a DLL extension.

May 15 '06 #8

P: n/a
> I believe what he is saying is that the Right-Click "Add reference"
feature on Visual Studio will refuse to add the reference until the
assembly has a DLL extension.


The EXE projects in my solution show up as available for reference from the
other projects.
May 15 '06 #9

P: n/a
I think that is a 2.0 feature IIRC.

--
William Stacey [MVP]

"PIEBALD" <PI*****@discussions.microsoft.com> wrote in message
news:AA**********************************@microsof t.com...
|> I believe what he is saying is that the Right-Click "Add reference"
| > feature on Visual Studio will refuse to add the reference until the
| > assembly has a DLL extension.
|
| The EXE projects in my solution show up as available for reference from
the
| other projects.
May 16 '06 #10

P: n/a
William Stacey [MVP] <wi************@gmail.com> wrote:
I think that is a 2.0 feature IIRC.


Well, it's a Visual Studio 2005 feature. Even in .NET 1.1 you can get
the command-line compiler to add a reference to an executable, but to
get it to work in VS.NET 2003 you have to hack the project file a bit.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 16 '06 #11

P: n/a
>>> The EXE projects in my solution show up as available for reference from the other projects. <<<

But if you try adding it (in VS2003), it will give an error.

May 16 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.