CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [RESOLVED] Generic Class Event & Unique Subscribers

  1. #1
    Join Date
    Nov 2006

    [RESOLVED] Generic Class Event & Unique Subscribers


    The title may not be the best but here is my problem. I have a class that has to load images and xml files asynchronously. Originally i just used to do it Synchronously so i could just do something like:

    // Make Image & Populate it with the image resource
    Image tempImage = ResourceManager.getInstance().fetchResource("testImage.png", ResourceType.IMAGE_RESOURCE);
    However with doing things asynchronously i need to sort out a callback system. So i was thinking of adding a "ResourceLoaded" event. Although there are times when between 1-100 things could be loading up at once, so if i have 100 objects all subscribed to the "ResourceLoaded" event from what i could see it would be anarchy, as each time one of files loads i think it would let all the subscribers know so you may end up getting a completely different resource to the one you requested...

    So i was wondering if anyone had any experience with this sort of thing, as ideally i need it to do the following:

    - User specifies a callback function (to handle the loaded resource data/failed loading)
    - User requests a resource
    - Resource loader attempts to load the file
    - Resource loader sends the loaded data to the success/failure callback
    - Users callback deals with the loaded data and uses it

    I dont quite know how to make sure the correct callback is called when its resource loads/fails, but thats the main stumbling block i have at the moment... any advice would be great!
    Last edited by Grofit; November 25th, 2008 at 03:13 AM.

  2. #2
    Join Date
    Nov 2006

    Re: Generic Class Event & Unique Subscribers

    Thought i would elaborate more, as it seems no one knows what im on about or doesnt know how to help.

    Basically im trying to do a callback system, so a user can request a resource to be loaded and give it a function to callback once its done, the callbacks need to be unique as there may be xml data loaded, image data loaded etc. So because of this i will need to be able to make sure when the resource is loaded and the event is fired it is directed to the correct callback.

    I think the problem stems from the object that deals with loading resources being a singleton, so it handles a number of objects requesting resources, so i need to think of a way to track what async loader is linked to what callback... i guess i could have a list of loaders and callbacks and just try to join them up when completed...

    Again any advice would be great!

  3. #3
    Join Date
    Nov 2006

    Re: Generic Class Event & Unique Subscribers

    I ended up doing a factory style system so rather than the static manager worrying about loading it internally, the fetchResource function returns a pre populated loader with events to attach onto, then when you want it to load you call the "fetch()" function and it runs off and does it.

    Again, its a vauge question and for a specific problem, so may not be of any help to others...

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)