Results 1 to 12 of 12

Thread: Enumerate class instances system wide...

  1. #1

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Enumerate class instances system wide...

    Is such a thing possible? For example, I have an app that has a form, MyForm. Is it possible to find all instances of MyForm that exist at the time I look for them?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    if you want the forms in your App, you can do the following...

    otherwise , i've put a system wide enumeration below it, hope it gets you on the way

    VB Code:
    1. [COLOR=BLUE]Private[/COLOR] [COLOR=BLUE]Sub[/COLOR] Button1_Click([COLOR=BLUE]ByVal[/COLOR] sender [COLOR=BLUE]As[/COLOR] System.Object, [COLOR=BLUE]ByVal[/COLOR] e [COLOR=BLUE]As[/COLOR] System.EventArgs) [COLOR=BLUE]Handles[/COLOR] Button1.Click
    2.         [COLOR=BLUE]Dim[/COLOR] objType() [COLOR=BLUE]As[/COLOR] Type = Reflection.Assembly.GetExecutingAssembly.GetTypes()
    3.         [COLOR=BLUE]Dim[/COLOR] x [COLOR=BLUE]As[/COLOR] [COLOR=BLUE]Integer
    4.  
    5. [/COLOR]        [COLOR=BLUE]For[/COLOR] x = LBound(objType) [COLOR=BLUE]To[/COLOR] UBound(objType)
    6.             MessageBox.Show("forms in your app are: " & objType(x).Name)
    7.         [COLOR=BLUE]Next
    8. [/COLOR]    [COLOR=BLUE]End[/COLOR] [COLOR=BLUE]Sub[/COLOR]

    but if you want system wide , maybe you need to enumerate the processes , like this.....
    VB Code:
    1. [COLOR=BLUE]Private[/COLOR] [COLOR=BLUE]Sub[/COLOR] Button2_Click([COLOR=BLUE]ByVal[/COLOR] sender [COLOR=BLUE]As[/COLOR] System.Object, [COLOR=BLUE]ByVal[/COLOR] e [COLOR=BLUE]As[/COLOR] System.EventArgs) [COLOR=BLUE]Handles[/COLOR] Button2.Click
    2.         [COLOR=BLUE]Dim[/COLOR] procs() [COLOR=BLUE]As[/COLOR] Process = Process.GetProcesses()
    3.         [COLOR=BLUE]Dim[/COLOR] x [COLOR=BLUE]As[/COLOR] [COLOR=BLUE]Integer
    4.  
    5. [/COLOR]        [COLOR=BLUE]For[/COLOR] x = LBound(procs) [COLOR=BLUE]To[/COLOR] UBound(procs)
    6.             ListBox1.Items.Add(procs(x).ProcessName & "  : " & procs(x).MainWindowHandle.ToInt32)
    7.         [COLOR=BLUE]Next
    8.  
    9. [/COLOR]    [COLOR=BLUE]End[/COLOR] [COLOR=BLUE]Sub[/COLOR]
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    That enumerates all types in an assembly. But will it enumerate the instances of a type that may be created and destroyed at runtime?
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    not tried that yet lol, but something you may recognize lunatic...
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994
    .....
    Heading for the great escape
    heading for the rave
    heading for the permanent, holiday.
    very good album is brave, although seasons end is my favourite post - fish marillion album. seen em around 15 times or so since the mid 1980's in concert
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  5. #5
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Originally posted by dynamic_sysop
    very good album is brave, although seasons end is my favourite post - fish marillion album. seen em around 15 times or so since the mid 1980's in concert
    Yes, Seasons End is my favorite too.
    I love them though never had the chance to see them in concert (due to living in Iran), however I am moving to Canada soon and hope they care to come to Vancouver and play there. Recently I had a chance to see a show of them playing at MCM cafe in Paris. They played "The Great Escape" just great. As a Marrillion fan you may be an Eloy fan too? Right?
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  6. #6
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    i have listened to eloy, but not really got in to them. my cousin in holland has all their stuff though ( he's mad on prog rock ), he used to help running the dutch marillion fanclub. good to see someone else with great tastes in music on here
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  7. #7
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Originally posted by dynamic_sysop
    good to see someone else with great tastes in music on here
    Especially if from Axis of Evil
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  8. #8

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Hey, stop hijacking my thread, or I'll give out some serious ass punching!

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Originally posted by crptcblade
    Hey, stop hijacking my thread, or I'll give out some serious ass punching!

    Ass punching? I thought you were supposed to kick the ass!


    If you mean for a specific project then you could use some form of factory design to control the different instances. You'd think that the GC has to track instances and we can sort of access it that we could get the info but I couldn't find away to get instance information.
    Last edited by Edneeis; Aug 11th, 2003 at 12:03 PM.

  10. #10

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Super dooper bump!

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  11. #11
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Hmm I dont know if it registers classes System or App-wide but you could try designing classes that would have a static class that everytime you'd instanciate a class you'd add a reference to that static method

    hmm hope you understood :S
    \m/\m/

  12. #12

    Thread Starter
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    I understand, but I was under the understanding that it only be in the scope of the application. I'll have to test some things out then, thanks.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

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