Results 1 to 7 of 7

Thread: Events Not Working

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    5

    Events Not Working

    Hi I'm new to the DCOM programming, but I had a question that hopefully you could answer. I've created an client/server application where multiple clients can be opened at the same time to change data values. However, when one client changes a value, all other clients should be informed instantaneously of the change through a Raised Event. I've implement the classes using the Singleton Object pattern. The problem is that I can raise events only on the client which created it, however, the other clients do not see the events. I'm wondering why this could be happening. I suspect a possible DCOMCNFG problem, but I have tried everything and it still does not work. My other suspicion is that in fact each client when started creates a separate instance of the server object (though it has global state variables) which in turn do not allow the clients to all see the same information.

    To make this short, I was wondering, if even I could have a small test sample, how to make a client/server VB app in which all the clients would be notified with events if one client made a change.

    Thank You.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Sorry I can't help but if you do figure it out then let me know please or post the answer back.

  3. #3
    Hyperactive Member SoftwareMaker's Avatar
    Join Date
    Mar 2001
    Location
    Elbonia with Dilbert and Wally
    Posts
    322
    I think your second suspicion is right. You created a new server object which is why the other clients dont get a raise event. (This is provided that you have implemented withevents keyword and write the necessary codes in the events sub)

    RaiseEvents in VB6 has many advantages, the best that it is easier to code and maintain but it doesnt give the client much control such as which client should be informed first. Before that, we use OLECallbacks before VB6. Altho that is harder to understand and conceptualize, OLECallbacks are more powerful as they give the client more control. I think what you need is an OLECallback object...altho I am quite surprised you cant do the same with a RaiseEvent. Let me look more into it.

    Keys to undertanding OLECallbacks:
    1) An object that raises events has no control over the order in which clients receive its events. By contrast, a component making callbacks can control the order in which clients are called back

    2)When an object raises an event, all of its clients handle the event before the object that raises the events get control again. However a component making callbacks gets control after each call to the client...In other words, its Asynchronous...

    3)A server making callbacks will receive errors that occur within the callback method of the client and it must be prepared to handle it.

    4)One of the most compelling reasons for using an OLECallback is when early binding to an object is just not possible. BUT if they can be early-bound, they are FASTER than events because they can be vtable-bound.

    Let me look more into your problem. a RaiseEvent method should still do the trick but if you want, give me your email address and I will email a sample OLECallback object to you.
    Last edited by SoftwareMaker; Aug 17th, 2001 at 12:48 AM.
    William T
    Software Architect / Chief Software Developer
    Softwaremaker.Net Pte Ltd
    http://www.Softwaremaker.net

    *** Things are always the darkest before they go pitch black ***

  4. #4
    Hyperactive Member SoftwareMaker's Avatar
    Join Date
    Mar 2001
    Location
    Elbonia with Dilbert and Wally
    Posts
    322
    //////////////////////////////////////////////////////////////////////////
    Important In an apartment-model DLL, a new apartment is created for each client thread that requests objects that the DLL provides. The first time a client thread requests such an object, Sub Main executes for the new apartment. A DLL cannot create threads of its own.

    Important The "global" in "global object" simply means that the methods and properties of the object added to the global name space of your project, so that they can be used without first declaring an object variable. It does not mean that there is only one such object, or that multiple client applications can share a single object. An instance of the class will be created for each client that uses methods of the class without qualifying them. Only one such global object will be created for each client.

    This means that you cannot use global data to communicate between objects on different threads.

    Note Objects in different apartments can only communicate with each other if a client passes them references to each other. In this case, cross-thread marshaling is used to provide synchronization. Cross-thread marshaling is almost as slow as cross-process marshaling.

    Note In addition to maintaining a separate copy of global data, a Sub Main procedure is executed for each new apartment (that is, for each new thread). Otherwise, there would be no way to initialize global data for the thread. This is discussed further in "Designing Thread-Safe DLLs" and "Designing Multithreaded Out-of-Process Components."
    //////////////////////////////////////////////////////////////////////////////////

    I hope this will at least help. Good luck.
    William T
    Software Architect / Chief Software Developer
    Softwaremaker.Net Pte Ltd
    http://www.Softwaremaker.net

    *** Things are always the darkest before they go pitch black ***

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Ok I was able to do it with callbacks and it wasn't as hard as I thought it would be. The project I am using it in is to complex to post a sample but if anyone wants code then let me know and I'll make a small sample project.

    I made a passport type component so the user could switch between different programs and share the info from only one log in. So it uses an activex EXE to share an object across different apps and it now has optional callbacks to raise events in all apps that are connected to the one global object.

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    5
    Thank You for the help,

    Could you please post a simple sample?

    Thank you.

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Here is the sample project. To test it run ExShareCallBackTest.exe (user head icon) if it gives you an 'ActiveX can't creat...' error then run the ActiveX EXE once to register it. Just double click it and it won't do anything, nothing will pop up or anything, its name is ExShareWCallBack.exe (key icon). Well I hope this helps. this is how I did it.

    To really see what it does you'll have to run multiple ExShareCallBackTest.exes which would will show the sharing or the info and call backs.

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