Codeunit instances

bijaljambusariabijaljambusaria Member Posts: 46
Dear All,

Can you please clarify what is the meaning of "codeunit instance"? What is single instance and multi instance codeunit? It would be great if the guidelines are supported with examples. :!:

Thanx

Comments

  • kinekine Member Posts: 12,562
    Are you sure that you are asking in correct Forum? It is about NAV or MS CRM?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • bijaljambusariabijaljambusaria Member Posts: 46
    I am sorry. I know I have made mistake of posting the topic in wrong forum but I dont know how to move this topic to Navision General... :(
  • AdministratorAdministrator Member, Moderator, Administrator Posts: 2,499
    [Topic moved from Dynamics CRM (formerly CRM) to Navision forum]
  • kinekine Member Posts: 12,562
    Instance - it is like Object and Class.

    If I have two variables of type Codeunit 80 (for example...)
      SalesPost.Blablabla;
      SalesPost2.Blablabla;
    

    I have two instances of the codeunit 80. If the function Blablabla works with global variables in the codeunit, the change through variable SalesPost will not be visible in SalesPost2 (there are two objects in memory, two separate memory area for each INSTANCE).

    But if I set the property SingleInstance = Yes, both variables will work with same instance of the codeunit, all global variables in the codeunit will be shared through all variables of type Codeunit 80.

    "Multi instance":
    SalesPost --- CU80
    SalesPost2 --- CU80

    "Single instance":
    SalesPost --- CU80
    SalesPost2 --/
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Miklos_HollenderMiklos_Hollender Member Posts: 1,598
    OK let's put it in some other way: probably the only time you'd use a singleinstance CU is whenever you write some interface routine that runs continuously and waits for data to appear for it to pick up on the disk or in an MSMQ queue etc.
  • kinekine Member Posts: 12,562
    Or because you want to optimize setup table readings (read once per client run), or you need to pass parameters between objects - in cases when you need "shared" memory space which can be used for communication... 8)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • bijaljambusariabijaljambusaria Member Posts: 46
    Thanx... ! =D>
  • AkilaAkila Member Posts: 19
    Hi All
    Codeunit has two type of instances. i don't know the Practical use of codeunit single instance and multiple instance. If anyone explain with examples, it will be very understandable to me...... O:)
    Dream is not the thing, what you see in the sleep. Dream is the thing, which does not let you sleep.
  • kinekine Member Posts: 12,562
    and do you understand the theoretical part of this?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • MTCMTC Member Posts: 159
    This is the problem, if somebody does not know the basic OOP theory it becomes rather difficult to explain. This is a NAV forum not an OOP one.

    A single instance codeunit is basically one that can only exist as a single object. Once the object is created, it stays in memory until it is killed by closing of the company. Any new creations of this codeunit will not actually create a new object, but rather refer directly to the one that currently exists. All of its internal global variables and their states are kept over all references to the object.

    A multiple instance codeunit is exactly what it says on the tin. Every new creation of the codeunit creates a new object that has its own set of variables in their own state. It is also deleted when it goes out of scope.
  • AkilaAkila Member Posts: 19
    Thanx \:D/
    Dream is not the thing, what you see in the sleep. Dream is the thing, which does not let you sleep.
Sign In or Register to comment.