Item Add not working on 3rd time

N

Neetu

We have a custom folder. inside outlook. we are dragging mail item from inbox
to this custom folder. we can add mail to folder(custom) from inbox then
again drag the mail item back to inbox. this step, for add and delete from
custom folder is happening 2 times only. after that if we tries to add same
mail item from inbox to custom folder, item doesn't add.
we are calling

Marshal.ReleaseComObject(mailselected);
mailselected = null;
each time when we deleting item from custom folder.

if we drag more than 1 items from inbox then to inbox, after each step one
mail item stops adding into custom folder.

any suggestion are welcome.

Thanks
Neetu
 
K

Ken Slovak - [MVP - Outlook]

I don't follow. Are you saying that you can't use the UI to do that or that
your ItemAdd event handler stops firing?

Usually if an event handler stops firing it's because there's no class level
declaration that will keep the event handling object or collection alive and
it goes out of scope and gets garbage collected. The fix for that is to
declare the collection at class level:

private Outlook.Items _items;

The other possibility is that by calling ReleaseComObject() you are
disconnecting the underlying object from the RCR. Are you getting any
exceptions like that? It's usually best to just set an object = null until
there's no possibility that you will need a reference to it later. For
example, if you have an item reference in class A and you pass that
reference to class B, if you then call Marshal.ReleaseComObject() on the
item in class B you are disconnecting it even for the class A reference. In
class B you should only set the object = null and call ReleaseComObject()
only when you release the object in class A.
 
N

Neetu

yes Dragging of same mail ietm from inbox to our custom folders doesnot work
after 3 conscecutive drags from inbox ->custom folder->inbox,
I am able to drag another item from inbox to custom folder but not the item
which has completed 3 times drag and delete from custom folder.
each time after delete and add event i m calling
ReleaseComObject(mailitem)

There is no exception while calling this method.
before call return value of this method is showing equal to 1.
after call it is 0. or some time -1.
 
K

Ken Slovak - [MVP - Outlook]

As I said, try not using Marshal.ReleaseComObject and instead just set the
item to null and see if that makes any difference. Otherwise you're going to
have to do detective work to see where and how your event handler is going
out of scope or being released.
 
N

Neetu

Hello ken,
If i don't call Marshal.ReleaseComObject and setting mailobject=null
in that case same mail cannot copied to custom folder again after moving it
back to inbox. if we call Marshal.ReleaseComObject after item remove event
, it can copied to custom folder 3 times.

Add item event works for other mail item
 
K

Ken Slovak - [MVP - Outlook]

Then you will have to do some detective work. There's no way for me here to
know what's going on exactly in each piece of your code, only you can do
that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top