Cru Dy Cru Dy - 1 year ago 108
C# Question

c# Passing Data from project to project

My Solution hold 2 Projects :
the first one : basically a login system where the user login

I have a var that hold the id of the actual connected user :

public static int UserID;

the var take a value from the database when the user login :

User_info.UserID = Convert.ToInt32(Table.Rows[0][0]);
User_info.UserName = Table.Rows[0][1].ToString();
User_info.Password = Table.Rows[0][2].ToString();
User_info.Email = Table.Rows[0][3].ToString();
User_info.Pack = Convert.ToInt32(Table.Rows[0][4]);
MessageBox.Show("" + User_info.UserID);

as you can see the UserID it takes it value from a table that hold the full user info .
i checked that the value its not actually null or neither 0 it always take the value of that table

so in the other project I added the first project as a reference of course and i used it :

using Bufferz_Server.Network___Acces;

So I tried to use the UserID Value :

private int UserID = User_info.UserID;

I run the first project and login to set the
value then i run the other project while the first one is still debbuging ..
but i always get the value 0 in the seconde project
I don't know if i miss something ?

Thank you !

Answer Source


When you reference "Project 1" in "Project 2" and put using Bufferz_Server.Network___Acces; in it, you actually just import code from "Project 1".

You do that to reuse code from other pojects (Usually .dll's).
Afterwards your "Project 2" depends on "Project 1".

This is just for reusing code! The projects share no memory at all.

So no variables that come from the process of "Project 1" will ever reach the process of "Project 2" unless you specificly tell "Project 2" or do some kind of memory sharing.


You could use some sort of communication as for example TCP/UDP sockets to send your stuff over to the other process.


You can use Memory Mapped Files here is a guide for that.

I recommend you the latter.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download