Results 1 to 5 of 5

Thread: Arggh. I actually need help(static/shared variables)

  1. #1

    Thread Starter
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913

    Arggh. I actually need help(static/shared variables)

    Hey guys, I need a hand.

    I have a dll that has a static hashtable(object collection) variable that is public. One executable loads it and instantiates the dll and sticks some objects into that hashtable. Now a second exe is supposed to instantiate the dll and with the variable being statis/shared, the second exe should get the value of the hashtable variable as it has been populated by the first exe. But unfortuantly it does not. The varaible is blank. Am I missing anything that I need to do other than make the shared?

    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Yes Cander you are indeed missing something .

    If a variable is declared static or shared in a class, that variable will be invisible if that class is instanitated.

    eg
    Code:
    public class MyClass
    {
       public static int myInt;
       public int myNextInt;
    
       public MyClass()
       {}
    
    }
    Code:
    MyClass mc = new MyClass();
    mc.myNextInt = 1; //This is the only member that will show up
    
    //to get myInt you would have to do this
    MyClass.myInt = 1;
    If you want to get values into a static or shared variable, do not instantiate the class with those static or shared variables. Hope that helped
    Dont gain the world and lose your soul

  3. #3

    Thread Starter
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    hmm..thought I had tried that before. Ill check again and see if that does it. Thanks.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Actually I think the problem is wanting to share the same object across different exes or AppDomains. You can use remoting to share the same instance or find a way to serialize the object and deserialize it to the other exe. Hopefully I'm wrong though and DevGrp is right or there is an easier way.

  5. #5
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    I might be mistaken, but I don't believe a dll is shared between applications. It runs in-process.
    Your static/shared variable will be visible for one application only.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width