Sukhani
asked on
communicate between two .net programs
Hello Everyone,
I have a Windows Form Application which has been developed in .net 3.5. The language used to develop is VB.NET. It a charting program and shows stock market charts to users.
Now I have made another program in vb.net (same .net version) and I want this program to interact with the one I made before. The new program is like a small scripting language. So for example: if i run a script then its output should be reflected in the other program. How can the two programs communicate ? Both will be running on same systems. No remote stuff.
Plus I have several functions which are written in first program. Is it possible for the other program which is an .exe also to call the functions of the other one if I make sub/function public or something. The reason is we can calls functions or subs if we include a dll. But can one exe calls functions/sub of another exe (if both program are in .net).
I will be glad if anyone can help me out.
Thank You,
Cheers,
Saurabh
I have a Windows Form Application which has been developed in .net 3.5. The language used to develop is VB.NET. It a charting program and shows stock market charts to users.
Now I have made another program in vb.net (same .net version) and I want this program to interact with the one I made before. The new program is like a small scripting language. So for example: if i run a script then its output should be reflected in the other program. How can the two programs communicate ? Both will be running on same systems. No remote stuff.
Plus I have several functions which are written in first program. Is it possible for the other program which is an .exe also to call the functions of the other one if I make sub/function public or something. The reason is we can calls functions or subs if we include a dll. But can one exe calls functions/sub of another exe (if both program are in .net).
I will be glad if anyone can help me out.
Thank You,
Cheers,
Saurabh
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
While I look into named pipes and remoting, is there a way my one exe can access functions/subs in other one. I have code for both. Putting code in Dll wont be easy as they are written in program and I would need to make a lot of changes. Or can I make a new dll which I can include in my first program and pass my exe to dll by reference and then it can access functions.
As I said, you can compile the common code into a DLL and use that in both EXEs.
Sorry I did not read your full comment.
Making changes to move the code to DLL will save you from a lot of headache in future when you have same code in multiple places and you need to debug/change the code.
Making changes to move the code to DLL will save you from a lot of headache in future when you have same code in multiple places and you need to debug/change the code.
ASKER
Compiling common code into a dll will be a lot of work as I have a lot of code and they are written in such a way that I will have to make a lot of changes.
ASKER
While I check if I can compile common code into dll, is there any alternative. Can I write a dll which I can include in my first program and it can call functions in my exe program.
You might try exposing your public methods to COM and using Interop to automate, much as you would in an Office Application.
Here's an article that might give you some ideas: http://www.codeproject.com/KB/COM/nettocom.aspx
Here's an article that might give you some ideas: http://www.codeproject.com/KB/COM/nettocom.aspx
One way is to use reflection to call functions in an assembly.
http://www.java2s.com/Code/VB/Development/GetMethodinformationandinvokeMethodusingReflectionAPI.htm
http://www.java2s.com/Code/VB/Development/GetMethodinformationandinvokeMethodusingReflectionAPI.htm
is there a way my one exe can access functions/subs in other one.You can add a reference from one .exe to the other, much like using a DLL. The "referenced" .exe will work just like a DLL would, so it won't be "running" on its own; it will effectively be treated like a library of functions.
ASKER
I tried the .net named pipe example which was given in msdn, it didnt seem to work the way I wanted.
Is there a way to my exe or dll can interact with my another exe and pass arrays and get value. Possibly using WCF or something easier. Can anyone give an example please ?
Is there a way to my exe or dll can interact with my another exe and pass arrays and get value. Possibly using WCF or something easier. Can anyone give an example please ?
>Can anyone give an example please ?
You question is not about how to show a message box to which we can show the example with
Messagebox.Show("your message", "title", ...)
The question is generic and huge. You have many options. If you take the WCF route, it would be useful in future as well.
You question is not about how to show a message box to which we can show the example with
Messagebox.Show("your message", "title", ...)
The question is generic and huge. You have many options. If you take the WCF route, it would be useful in future as well.
ASKER
Well by example I mean a small code or so that shows how to do basic communication between two programs. For e.g. palpatin suggested that .net remoting is relatively easy. So a small code project that shows basic stuff. I can then expand or experiment on it.
If I can call function/sub in my exe then it will be useful. I dunno if .net remoting will allow that. WCF is complex I guess.
If I can call function/sub in my exe then it will be useful. I dunno if .net remoting will allow that. WCF is complex I guess.
.NET remoting allows to make an object REMOTE so that you can call its functions from other EXEs. But you may have to rewrite your code. I would not be able to do a sample project (got plenty of my own to do). May be someone else has something to offer.
ASKER
Let me try my hand in .net remoting and wcf.
Though what I did right now was create a sample exe with a public function. Include that exe in a dll and call its function. Though it worked but I think if the exe is running then it won't call the running exe's function. It will make a copy and call like a non running program. Am I right?
Though what I did right now was create a sample exe with a public function. Include that exe in a dll and call its function. Though it worked but I think if the exe is running then it won't call the running exe's function. It will make a copy and call like a non running program. Am I right?
I think Yes. Calling a function in an exe from a DLL is the opposite of what is usually done though.
ASKER
I was able to write code in vb.net that uses WCF and creates 2 servers so that 2 programs can independently exchange information/data. The server has to be on at all times though. I hope that does not create any load.
I think its initiated by user request so there should not be any load.
ASKER
Actually its not like that. I want communication both ways in the two exe. So when the exe start I create server in both and client in both. Whenever one exe gets request it responds. This way servers are running at all times. So is this okay ?
I dont see any problem with that.
ASKER
Here when we use http://localhost:8001. The 8001 or 8000, this has to be unique right. This is port, so what numbers are generally used.
Its totally random. Preferably use a number that has less chances of being repeated. Such as 6721
if you have the code you can reference the dlls