04-24-2010 06:34 AM
I'm fighting with next problem.
I have note manager application. I want to inject it to email application. I've added ApplicationMenuItem.
How it should work:
1. User hits menu item
2. If application is opened:
2a. Application inserts new note
2b. Item opens persistent store and save note.
I'm sending global event "add note" in menu item and wait for global event "handled" (sent from application). I don't like the design that depends on "waiting". But currently don't have idea how to implement this functionality.
OK, the problem:
MenuItem as GlobalListener isn't invoked.
1. Is it allowed one global listener per application?
2. What do I do wrong?
04-24-2010 09:12 AM
Sorry, I'm not clear on what you are asking.
The point of your menu items appears to be to save the data. So you have two options:
a) Use a Global Event and pass the data to be saved to your application. This seems perfectly reasonable. I'm not sure why you would have to wait for the Global Event handled, and most importantly, if you are doing this, you might be blocking the Event Thread of the mail application. SO you need to popup a Please wait type screen. This is starting to get quite complicated, so I would avoid the wait. The issue however with this approach, is that you appear not to be confident that your Application's global event processing works correctly, so are unwilling to tell the user that the data has been saved until you know for sure it has been. I'm not so sure I would be that worried.
b) The other alternative appears to the the one you have chosen, that is write your data into a shared bit of persistent store. So your application can get at it, but the email application can add notes to it. This is run. Of course you will have to synchronize somehow to make sure that no process can be manipulating the notes collection while the email application is adding to it ( remember you have separate processes) but that is fairly standard processing. Of course a problem in this are could screw up the Email application, which your user's might not thank you for.
As you can see, no perfect solution. In your case, I would probably choose option (b), which appears to be the one your have gone with. However I would be very careful to make sure that the add will complete.
To answer your questions:
2. Don't know, would probably need to see your code. However if I was guessing, I would say that you have used a background application to add your listener, and you do not actually start this application (i.e. it does not 'enterTheDispatcher').