CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Join Date
    Apr 2009
    Posts
    18

    Re: static variables

    ok ill try this out..

  2. #17
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: static variables

    It could be, it is the easies case.

    nightscorpion, are mediat.test(4) and mediat.recieveEle(request) called in the same process, or in two separate processes (e.g. windows service and a client application)? If it would be two separate processes, you need more comlex solution, like a one based on WCF.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  3. #18
    Join Date
    Apr 2009
    Posts
    18

    Re: static variables

    They are two separate processes....one(A) is a console app and project B is a class library .

    so u mean to say i need to have WCF services like an LCS with a config file?

  4. #19
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: static variables

    WCF or remoting or any other kind of RPC, because as mentioned before, if there are two different proceses, which means two different app domains they, there are also two different "instances" of the Mediator type (the type is loaded in two different instances of CLR) which doesn't share anything, so the static doesn't work the way you know from case where there is only one process.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  5. #20
    Join Date
    Apr 2006
    Posts
    220

    Re: static variables

    Is the guy'z problem sharing and accessing data between two different processes?

    I don't think so. He has declared and initialized two separate instances of his class and every instance will have its separate data.

    Scorpion! if you want to access A's instance in B, make some public method in B which accepts A's instance and pass it your declared instance.

    Correct me someone if I am wrong.
    Last edited by nabeelisnabeel; May 13th, 2009 at 01:36 AM. Reason: extra

  6. #21
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    210

    Re: static variables

    Quote Originally Posted by nightscorpion View Post
    They are two separate processes....one(A) is a console app and project B is a class library .
    If the class B is used in your console it is the SAME process
    as long you do not start a 2nd exe or create 2nd process.

  7. #22
    Join Date
    Apr 2009
    Posts
    18

    Re: static variables

    Hey ,
    @MNovy : I tried out the code which u sent me..in ur code u could use the instance as a parameter in ur main coz u have created the instance in the same class itself. Whereas in my case one instance is created in main (project A) and the other instance in Project B...AND both are having their references to C. So between A and B there are no references at all.

    to be more precise on wht i am working with project A is my host which is a console app AND which also initiates a Workflow instance . Project B is suppose to start the Enterprise Architect and open a Project(when the project is opened it is in the the form of a tree view.). I select an element from the treeview and it should get this workflow instance which was created in my Project A.
    To make this more simpler i used a int instead of a workflow instance to make it easier to understand in the forum.


    @nabeelisnabeel : as i said both are having their references to Project C it hardly matters if i declare the methods as public ..as they are 3 different projects

    i had created the project C coz A and B was creating a circular dependency and also because A is a console app and B a class library.

    i have not much info abt WCF..probably it might work out with it.

  8. #23
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    210

    Re: static variables

    Quote Originally Posted by nightscorpion View Post
    Hey ,
    @MNovy : I tried out the code which u sent me..in ur code u could use the instance as a parameter in ur main coz u have created the instance in the same class itself. Whereas in my case one instance is created in main (project A) and the other instance in Project B...AND both are having their references to C. So between A and B there are no references at all.
    Where is the problem? You can use the mechanics I mentioned here, too.

    Where is B created? In A?
    B has to be instantiated somewhere, isn't it?
    At this point, just pass the class you want to use there, too.

    So you create in A your instance of class C and set all values.
    Create instance of B in A (because you want to use it there) and pass the class C directly.

    BTW:
    Your code design seems to be very, very bad anyway.
    If you have to access an instance from other classes, you have to pass either the values by
    copying (call by value) them or by reference (call by reference).
    Both are explained in my previous code.
    Or make that class completely static, then it holds the values directly with no instance.

    There is NO other way man.
    Redesign your code!!!
    Last edited by MNovy; May 13th, 2009 at 11:51 PM.

Page 2 of 2 FirstFirst 12

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

Featured