Re: which event for readping pane fully instantiated.



The thread business is definitely critical when calling anything in the Outlook object model. Calling into the object model from a background thread will definitely hang or crash Outlook. But the timer in the Explorer wrapper class should be running on the main thread unless you set up a separate thread for it. Easy enough to check, just log or use Debug.WriteLine() with this:

string currentThread = Thread.CurrentThread.ManagedThreadId.ToString();

I've run into threading problems when calling to display a form with a Web browser control on it from a WordMail item, since that's running in a different process and thread, and the .NET Web browser control is really a wrapped Active-X control. In cases like that I've had to use code something like this:

// main Connect class:
private static System.Threading.SynchronizationContext _syncContext = null;

// in OnStartupComplete()
if ((_explorers.Count > 0) || (_inspectors.Count > 0))
{
if ((_syncContext == null) && (System.Threading.SynchronizationContext.Current != null))
{
_syncContext = System.Threading.SynchronizationContext.Current;
}
}

Then in my calls to the form with the Web browser control from WordMail I use code like this:

try
{
object[] args = { previewHTML, _stationeryToUse };

System.Threading.SendOrPostCallback callback = new System.Threading.SendOrPostCallback(PreviewThreadHelper.InitPreviewBox);

Connect.SyncContext.Post(callback, args);
}

Connect exposes a property called SyncContext that returns/sets the _syncContext thread object.

PreviewThreadHelper is a separate class that has an InitPreviewBox() method that takes an Object state argument passed from the synchronizer caller. The code there does the actual initialization and displaying of the preview form that has the browser control.

You can see if you can adapt that sort of code to what you need to do, calling back to the main UI thread that you picked up in the OnStartupComplete() handler.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"BatKing" <BatKing@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:C0FD321A-778C-4C72-8F94-66EF34CE6987@xxxxxxxxxxxxxxxx
Hi Ken,

I have tried what you suggested. However it seems during the _timer_Elapsed
event, I cannot touch any UI stuff. (ie, finding the reading pane window and
create my button). if I put my method, findReadingPaneAndAddButton(), which
finding the reading pane window and creates the button, then the whole
outlook will freeze (sometime ramdonly).

in the following example, the author mention the UI thread. and it seems I
am facing the exactly problem. just imaging what happen if the explorer
window (the sibling window) doesn't initialize fast enough (not in this case
but just a example) and I need a timer event to find the explorer window.

http://www.codeproject.com/KB/office/additional_panel_Outlook.aspx

"In any process/application, there should always be just a single thread
which executes the message loop of all child windows - the UI thread. Thanks
for us, the call to OnStartupComplete (like all calls of the
IDTExtensibility2 interface) is made from the UI thread, which is very
important because we are going to create the PanelContainer window and we
will assign it as a child of the Outlook main window. If this call was made
from another thread, we would have bigger problems because the PanelContainer
instance would be created out of the UI thread, which would cause big
stability issues."

I think I am facing the "bigger problems" and "big stability issues".

Thanks
Leon

.


Loading