none
Outlook Folder Icons using Secondary thread. RRS feed

  • Question

  • Hi,

    I am kinda stuck and ran out of ideas which is the reason I need help. I am pretty new to multi threading concept in C# .net. Well I am building an outlook 2010 COM add-in in visual studio 2010 using .net 4.0.

    When outlook starts, I create a PST, then add custom folders to it and then assign custom icons from resource file to those folders and sub folders. I used the code example provided here http://msdn.microsoft.com/en-us/library/ff869281.aspx to convert bitmaps to StdPicture. It works fine when I execute the code from the main thread but when I execute the same code through secondary/child thread everything gets executed without any exceptions/errors but Icons to the folders does not show up. 

    This is how I start the thread

    Thread initializeThread = new Thread(new ThreadStart(Initialize));

    initializeThread.Start();


    This is how I set Icon

    stdole.StdPicture MYICON = PictureDispConverter.ToIPictureDisp(resFiling.myIcon) as stdole.StdPicture;
    oFolder.SetCustomIcon(MYICON);

    Any help/ideas are welcomed and would be a step forward.

    Thanks

    Mani 


    MS


    Friday, May 25, 2012 12:40 AM

Answers

  • IPictureDisp objects cannot be passed across process or thread boundaries. That's a known limitation.
     
    Aside from what Damian mentioned about not using anything from the Outlook object model in a background thread (it will hang or crash Outlook), the icons would have to be added in the same process and thread as the addin.
     
    See http://msdn.microsoft.com/en-us/library/ff869281.aspx for information on SetCustomIcon() including the image and process limitations.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "manidollars" <=?utf-8?B?bWFuaWRvbGxhcnM=?=> wrote in message news:acf48fb3-54e3-463e-bfe8-644708038fc8...

    Hi,

    I am kinda stuck and ran out of ideas which is the reason I need help. I am pretty new to multi threading concept in C# .net. Well I am building an outlook 2010 COM add-in in visual studio 2010 using .net 4.0.

    When outlook starts, I create a PST, then add custom folders to it and then assign custom icons from resource file to those folders and sub folders. I used the code example provided here http://msdn.microsoft.com/en-us/library/ff869281.aspx to convert bitmaps to StdPicture. It works fine when I execute the code from the main thread but when I execute the same code through secondary/child thread everything gets executed without any exceptions/errors but Icons to the folders does not show up. 

    This is how I start the thread

    Thread initializeThread = new Thread(new ThreadStart(Initialize));

    initializeThread.Start();


    This is how I set Icon

    stdole.StdPicture MYICON = PictureDispConverter.ToIPictureDisp(resFiling.myIcon) as stdole.StdPicture;
    oFolder.SetCustomIcon(MYICON);

    Any help/ideas are welcomed and would be a step forward.

    Thanks

    Mani 


    MS



    Ken Slovak MVP - Outlook
    Friday, May 25, 2012 12:59 PM
    Moderator

All replies

  • general rule using any office API (which also mean outlook object model) : it can only be used from main UI thread. If you want to manipulat outlook objects from secondary threads you have to either write code using c++ (or equivalent) using extended MAPI or buy Redemption which will expose extended mapi through vb or .net bindings. Event then you have to understand that outlook assumes that he is the only one using extended mapi and caches a lot of things or startup/first use, so ilm not sure that setting this icon on secondary thread will make outlook realize that icon display has to be refreshed.
    Friday, May 25, 2012 6:47 AM
  • IPictureDisp objects cannot be passed across process or thread boundaries. That's a known limitation.
     
    Aside from what Damian mentioned about not using anything from the Outlook object model in a background thread (it will hang or crash Outlook), the icons would have to be added in the same process and thread as the addin.
     
    See http://msdn.microsoft.com/en-us/library/ff869281.aspx for information on SetCustomIcon() including the image and process limitations.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "manidollars" <=?utf-8?B?bWFuaWRvbGxhcnM=?=> wrote in message news:acf48fb3-54e3-463e-bfe8-644708038fc8...

    Hi,

    I am kinda stuck and ran out of ideas which is the reason I need help. I am pretty new to multi threading concept in C# .net. Well I am building an outlook 2010 COM add-in in visual studio 2010 using .net 4.0.

    When outlook starts, I create a PST, then add custom folders to it and then assign custom icons from resource file to those folders and sub folders. I used the code example provided here http://msdn.microsoft.com/en-us/library/ff869281.aspx to convert bitmaps to StdPicture. It works fine when I execute the code from the main thread but when I execute the same code through secondary/child thread everything gets executed without any exceptions/errors but Icons to the folders does not show up. 

    This is how I start the thread

    Thread initializeThread = new Thread(new ThreadStart(Initialize));

    initializeThread.Start();


    This is how I set Icon

    stdole.StdPicture MYICON = PictureDispConverter.ToIPictureDisp(resFiling.myIcon) as stdole.StdPicture;
    oFolder.SetCustomIcon(MYICON);

    Any help/ideas are welcomed and would be a step forward.

    Thanks

    Mani 


    MS



    Ken Slovak MVP - Outlook
    Friday, May 25, 2012 12:59 PM
    Moderator
  • Thanks Ken and Damian for the useful information. Although I was able to achieve the objective using background worker but I`ll surely avoid these situations in future.

    Thanks

    Mani


    MS

    Monday, May 28, 2012 4:40 AM
  • _If_ you achieved your goal using both OOM and background thread and it works on your machine - then you are just lucky and it will crash sooner or later. If you did this using other means - great.
    Monday, May 28, 2012 6:45 AM
  • Hi Damian,

    Yes at the moment it seems to work fine while using OOM and Background worker when outlook/Addin starts. However, I am not able to reassign custom icons while executing command from outlook UI. I have figured out the problem, which is context synchronisation of background worker thread. Some how the completed event of background worker is processed other than the thread on which it was created. I am not sure if its possible or not to synchronise it to the main thread.

    Does anyone knows about the background worker synchronisation?

    Well, you may be right that it might fail/crash, as I have noticed before that some things work perfectly fine on my machine but fails on the test machine. Especially with outlook while working on cache or online mode. But this requirement is quite important, that it is worth looking into. Would post if there`ll be any progress tommorrow. Too tired now.

    Thanks 

    Mani


    MS

    Monday, May 28, 2012 8:14 AM
  • there are multiple threads related to synchronization to main UI thread from background one, even when using the same component as you are using (background worker), please search a little, here is one example:

    http://social.msdn.microsoft.com/Forums/pl-PL/outlookdev/thread/891792ee-6bf5-4d32-9f93-fa22d7ff69e5
    Monday, May 28, 2012 8:25 AM