Problem combining examples from .Net API documentation

Discussion for developers using MailEnable.
Post Reply
mkucera
Posts: 5
Joined: Wed Jan 17, 2018 2:50 pm

Problem combining examples from .Net API documentation

Post by mkucera » Thu Aug 16, 2018 2:02 pm

I've run into an interesting situation while using the .Net API and i am wondering if this is a bug, or if it's expected behavior. It appears to be a bug to me, but I'm not the expert on this which is why i'm asking here. My application is fairly simple and i'm really only utilizing a couple of different methods in the MailEnable API. The high-level overview is that I'm watching a mailbox for incoming messages and when they are received i do some processing based on the message and then i delete the message. The overall structure of the application is this:

Code: Select all

                MailEnable.Store storeMessage = new MailEnable.Store();
                storeMessage.StoreFolder_Open("<MailboxName>", "INCOMING", "\\Inbox", storeMessage.MessageClass, 1);

                if (storeMessage.StoreFolder_FindFirstItem() == 1)
                {
                    do
                    {
			...
			... //Processing Occurs here
			...
		    }
                    while ((storeMessage.StoreFolder_FindNextItem() == 1));
		}

		storeMessage.StoreFolder_FindClose();
                storeMessage.StoreFolder_Close();
This code all works great. This essentially is the List Messages example found on page 20 of the .Net Reference documentation, translated into C#.

When the processing of a message has completed i want to delete the message, so somewhere in the do.. while loop i make a call to a delete message method. The Delete Message method originally looked like this:

Code: Select all

public static void DeleteSingleMessage(string messageID)
{
    long lResult = 0;
    MailEnable.Store storeMessage = new MailEnable.Store();
    storeMessage.StoreFolder_Open("<MailboxName>", "INCOMING", "\\Inbox", storeMessage.MessageClass, 1);

    lResult = storeMessage.StoreFolder_DeleteItem(messageID);
    lResult = storeMessage.StoreFolder_Save();
    storeMessage.StoreFolder_FindClose();
}
This code also works great and the message is deleted successfully. The problem that i am experiencing is what happens when i put these two code blocks together and attempt to process more than one message at a time. What happens is that the do.. while loop picks up the first message, processes & deletes it, but the while() condition doesn't pick up that there are more messages even though i can see that there are. I was able to trace this issue down to the

Code: Select all

    
    storeMessage.StoreFolder_FindClose();
statement in the DeleteSingleMessage() method. Even though this method instantiates a new MailEnable.Store object, calling the StoreFolder_FindClose() method on that object had ramifications on the other MailEnable.Store object from the caller. Now in normal object oriented programming this would never be the case. These are instance methods, not static methods, so calling a method on one object should be scoped to that one object alone. It should not impact the separate instance of the object.

I was able to resolve this issue by using a single instance of the MailEnable.Store object in my application and passing that in as a parameter to the delete message method.

Code: Select all

       public static void DeleteSingleMessage(string messageID, MailEnable.Store storeMessage)
        {
            long lResult = 0;
            lResult = storeMessage.StoreFolder_DeleteItem(messageID);
            lResult = storeMessage.StoreFolder_Save();
        }
When i made this change, then my do... while loop was successfully able to process multiple message. Is this the expected behavior? It looks like a bug to me. I appreciate your input.

Thanks for your time!
-Mark

Post Reply