RDOMail object is not working in different thread.

Status
Not open for further replies.
S

Sandeep K

Hi,

I am using RDOMail object to retrieve email data and setting user

properties. RDOMail object works fine in the main thread, 'ThisAddin thread',

(I am creating VSTO Add-in) but when I use same RDOObject in the worker

thread all function calls on the RDOMail object in debugger evaluates to

error "Function evaluation disabled because a previous function evaluation

timed out. You must continue execution to reenable function evaluation.".

Any clue how can i use RDOMail object in worker thread which is different

thread than ThisAddin thread.
 
K

Ken Slovak - [MVP - Outlook]

Sure. Set up the code to run with server side MAPI on a machine that never

has had Outlook installed.

What you want won't work. It will hang or crash Outlook and/or your addin

code. Think of a different method such as getting the information in the

foreground thread and then passing strings or whatever to the background

thread. Otherwise you're just causing yourself plus any other code running

on that machine nothing but headaches.

"Sandeep K" <SandeepK> wrote in message

news:B8E2F05E-56EC-4B71-B263-B2CCA4F7E6F8@microsoft.com...
> Hi,
> I am using RDOMail object to retrieve email data and setting user
> properties. RDOMail object works fine in the main thread, 'ThisAddin
> thread',
> (I am creating VSTO Add-in) but when I use same RDOObject in the worker
> thread all function calls on the RDOMail object in debugger evaluates to
> error "Function evaluation disabled because a previous function evaluation
> timed out. You must continue execution to reenable function evaluation.".

> Any clue how can i use RDOMail object in worker thread which is different
> thread than ThisAddin thread.
 
S

Sandeep K

Hi Ken,

The problem here is getting the information back from the background worker

thread. My scenario is like this:

I do some processing based on the content of email and then based on the

result I update the mail object properties. As I am using a background

workder thread for processing email content, I can now pass the email content

directly to the background worker. Now as background worker thread can not

access mail object, I believe I need the processing results to be passed back

to Main thread. Is there a way to pass the result back to main thread so that

It can set properties of the emails.
wrote:


> Sure. Set up the code to run with server side MAPI on a machine that never
> has had Outlook installed.

> What you want won't work. It will hang or crash Outlook and/or your addin
> code. Think of a different method such as getting the information in the
> foreground thread and then passing strings or whatever to the background
> thread. Otherwise you're just causing yourself plus any other code running
> on that machine nothing but headaches.

> >

>

> "Sandeep K" <SandeepK> wrote in message
> news:B8E2F05E-56EC-4B71-B263-B2CCA4F7E6F8@microsoft.com...
> > Hi,
> > I am using RDOMail object to retrieve email data and setting user
> > properties. RDOMail object works fine in the main thread, 'ThisAddin
> > thread',
> > (I am creating VSTO Add-in) but when I use same RDOObject in the worker
> > thread all function calls on the RDOMail object in debugger evaluates to
> > error "Function evaluation disabled because a previous function evaluation
> > timed out. You must continue execution to reenable function evaluation.".
> > Any clue how can i use RDOMail object in worker thread which is different
> > thread than ThisAddin thread.


>
 
K

Ken Slovak - [MVP - Outlook]

There are a few ways to pass data back and forth, depending on how you want

to implement something like that.

The simplest way is a set of public or internal data that both threads have

access to.

You can also get the thread context of the main thread and store that in an

accessible place, then a call from the background thread can pass data to a

procedure and synch that using a SendOrPost() callback.

I often use that methodology for WordMail related things for Outlook 2003,

where Word is running on a different thread than the Outlook process.

"Sandeep K" <SandeepK> wrote in message

news:21FA0EB2-903C-469E-9CD8-D9952FBA28A8@microsoft.com...
> Hi Ken,
> The problem here is getting the information back from the background
> worker
> thread. My scenario is like this:
> I do some processing based on the content of email and then based on the
> result I update the mail object properties. As I am using a background
> workder thread for processing email content, I can now pass the email
> content
> directly to the background worker. Now as background worker thread can not
> access mail object, I believe I need the processing results to be passed
> back
> to Main thread. Is there a way to pass the result back to main thread so
> that
> It can set properties of the emails.
 
D

Dmitry Streblechenko

All threads that use Extended MAPI must call MAPIInitialize. Outlook calls

it on its main thread, but if you create your own secondary thread, that is

your responsibility.

All creatable Redemption objects (including RDOSession) do that. Try to

create an instance of the RDOSession object on the secondary thread, sets

its MAPIOBJECT property to Application.Session.MAPIOBJECT from Outlook to

make sure the two share the same MAPI sessio, then retrieve RDOMail.

Dmitry Streblechenko (MVP)

-

"Sandeep K" <SandeepK> wrote in message

news:21FA0EB2-903C-469E-9CD8-D9952FBA28A8@microsoft.com...
> Hi Ken,
> The problem here is getting the information back from the background
> worker
> thread. My scenario is like this:
> I do some processing based on the content of email and then based on the
> result I update the mail object properties. As I am using a background
> workder thread for processing email content, I can now pass the email
> content
> directly to the background worker. Now as background worker thread can not
> access mail object, I believe I need the processing results to be passed
> back
> to Main thread. Is there a way to pass the result back to main thread so
> that
> It can set properties of the emails.

> " - " wrote:
>
> > Sure. Set up the code to run with server side MAPI on a machine that
> > never
> > has had Outlook installed.
>

>> What you want won't work. It will hang or crash Outlook and/or your addin
> > code. Think of a different method such as getting the information in the
> > foreground thread and then passing strings or whatever to the background
> > thread. Otherwise you're just causing yourself plus any other code
> > running
> > on that machine nothing but headaches.
>

>> > >

> >

>

>
>
>
>
>
>> "Sandeep K" <SandeepK> wrote in message
> > news:B8E2F05E-56EC-4B71-B263-B2CCA4F7E6F8@microsoft.com...
> > > Hi,
> > > I am using RDOMail object to retrieve email data and setting user
> > > properties. RDOMail object works fine in the main thread, 'ThisAddin
> > > thread',
> > > (I am creating VSTO Add-in) but when I use same RDOObject in the worker
> > > thread all function calls on the RDOMail object in debugger evaluates
> > > to
> > > error "Function evaluation disabled because a previous function
> > > evaluation
> > > timed out. You must continue execution to reenable function
> > > evaluation.".
> >> > Any clue how can i use RDOMail object in worker thread which is
> > > different
> > > thread than ThisAddin thread.

>

>>
 
S

Sandeep K

Thanks Dmitry sir,

I respect you a lot. Redemption provides a lot of functionality and we can't

complete our work without it. But we are very new for outlook add-in

development. I take a list rdomails in main thread and then process this list

on secondary thread for submission task to some server. Do you want me to

just send list of EntryIDs of mails and then create RDOMail object here in

secondary thread.

Lets say I do as I said above. How should i release RDOMails created in main

thread? (RDOMails are required in main thread as well since we set some user

property there)

Please advise.

"Dmitry Streblechenko" wrote:


> All threads that use Extended MAPI must call MAPIInitialize. Outlook calls
> it on its main thread, but if you create your own secondary thread, that is
> your responsibility.
> All creatable Redemption objects (including RDOSession) do that. Try to
> create an instance of the RDOSession object on the secondary thread, sets
> its MAPIOBJECT property to Application.Session.MAPIOBJECT from Outlook to
> make sure the two share the same MAPI sessio, then retrieve RDOMail.
> > Dmitry Streblechenko (MVP)
>

>

>

> -
> "Sandeep K" <SandeepK> wrote in message
> news:21FA0EB2-903C-469E-9CD8-D9952FBA28A8@microsoft.com...
> > Hi Ken,
> > The problem here is getting the information back from the background
> > worker
> > thread. My scenario is like this:
> > I do some processing based on the content of email and then based on the
> > result I update the mail object properties. As I am using a background
> > workder thread for processing email content, I can now pass the email
> > content
> > directly to the background worker. Now as background worker thread can not
> > access mail object, I believe I need the processing results to be passed
> > back
> > to Main thread. Is there a way to pass the result back to main thread so
> > that
> > It can set properties of the emails.
> > " - " wrote:
> >
> >> Sure. Set up the code to run with server side MAPI on a machine that
> >> never
> >> has had Outlook installed.
> >
> >> What you want won't work. It will hang or crash Outlook and/or your addin
> >> code. Think of a different method such as getting the information in the
> >> foreground thread and then passing strings or whatever to the background
> >> thread. Otherwise you're just causing yourself plus any other code
> >> running
> >> on that machine nothing but headaches.
> >
> >> > >>

> >>

> >
> >
> >
> >
> >
> >
> >> "Sandeep K" <SandeepK> wrote in message
> >> news:B8E2F05E-56EC-4B71-B263-B2CCA4F7E6F8@microsoft.com...
> >> > Hi,
> >> > I am using RDOMail object to retrieve email data and setting user
> >> > properties. RDOMail object works fine in the main thread, 'ThisAddin
> >> > thread',
> >> > (I am creating VSTO Add-in) but when I use same RDOObject in the worker
> >> > thread all function calls on the RDOMail object in debugger evaluates
> >> > to
> >> > error "Function evaluation disabled because a previous function
> >> > evaluation
> >> > timed out. You must continue execution to reenable function
> >> > evaluation.".
> >> >> > Any clue how can i use RDOMail object in worker thread which is
> >> > different
> >> > thread than ThisAddin thread.
> >
> >>


>
 
S

Sandeep K

I tried following two code segment in secondary thread but niether is

working. RDOMail evaluates to same error.

RDOSession rsession = new RDOSessionClass();

Outlook.Application app = new Outlook.ApplicationClass();

rsession.MAPIOBJECT = app.Session.MAPIOBJECT;

ArrayList rmails = new ArrayList();

foreach (string entryId in maillist)

{

RDOMail rmail = rsession.GetMessageFromID(entryId,

System.Reflection.Missing.Value, System.Reflection.Missing.Value);

rmails.Add(rmail);

}

or

RDOSession rsession = new RDOSessionClass();

rsession.MAPIOBJECT = Globals.AddinMain.Application.Session.MAPIOBJECT;

foreach (string entryId in maillist)

{

RDOMail rmail = rsession.GetMessageFromID(entryId,

System.Reflection.Missing.Value, System.Reflection.Missing.Value);

rmails.Add(rmail);

}

please advise.

"Dmitry Streblechenko" wrote:


> All threads that use Extended MAPI must call MAPIInitialize. Outlook calls
> it on its main thread, but if you create your own secondary thread, that is
> your responsibility.
> All creatable Redemption objects (including RDOSession) do that. Try to
> create an instance of the RDOSession object on the secondary thread, sets
> its MAPIOBJECT property to Application.Session.MAPIOBJECT from Outlook to
> make sure the two share the same MAPI sessio, then retrieve RDOMail.
> > Dmitry Streblechenko (MVP)
>

>

>

> -
> "Sandeep K" <SandeepK> wrote in message
> news:21FA0EB2-903C-469E-9CD8-D9952FBA28A8@microsoft.com...
> > Hi Ken,
> > The problem here is getting the information back from the background
> > worker
> > thread. My scenario is like this:
> > I do some processing based on the content of email and then based on the
> > result I update the mail object properties. As I am using a background
> > workder thread for processing email content, I can now pass the email
> > content
> > directly to the background worker. Now as background worker thread can not
> > access mail object, I believe I need the processing results to be passed
> > back
> > to Main thread. Is there a way to pass the result back to main thread so
> > that
> > It can set properties of the emails.
> > " - " wrote:
> >
> >> Sure. Set up the code to run with server side MAPI on a machine that
> >> never
> >> has had Outlook installed.
> >
> >> What you want won't work. It will hang or crash Outlook and/or your addin
> >> code. Think of a different method such as getting the information in the
> >> foreground thread and then passing strings or whatever to the background
> >> thread. Otherwise you're just causing yourself plus any other code
> >> running
> >> on that machine nothing but headaches.
> >
> >> > >>

> >>

> >
> >
> >
> >
> >
> >
> >> "Sandeep K" <SandeepK> wrote in message
> >> news:B8E2F05E-56EC-4B71-B263-B2CCA4F7E6F8@microsoft.com...
> >> > Hi,
> >> > I am using RDOMail object to retrieve email data and setting user
> >> > properties. RDOMail object works fine in the main thread, 'ThisAddin
> >> > thread',
> >> > (I am creating VSTO Add-in) but when I use same RDOObject in the worker
> >> > thread all function calls on the RDOMail object in debugger evaluates
> >> > to
> >> > error "Function evaluation disabled because a previous function
> >> > evaluation
> >> > timed out. You must continue execution to reenable function
> >> > evaluation.".
> >> >> > Any clue how can i use RDOMail object in worker thread which is
> >> > different
> >> > thread than ThisAddin thread.
> >
> >>


>
 
D

Dmitry Streblechenko

Yes, save the entry ids, then reopen the messages on the second thread using

RDOSession.GetMessageFormID

Dmitry Streblechenko (MVP)

-

"Sandeep K" <SandeepK> wrote in message

news:1C46E029-5D78-40EF-95D1-A5387CD14AB2@microsoft.com...
> Thanks Dmitry sir,
> I respect you a lot. Redemption provides a lot of functionality and we
> can't
> complete our work without it. But we are very new for outlook add-in
> development. I take a list rdomails in main thread and then process this
> list
> on secondary thread for submission task to some server. Do you want me to
> just send list of EntryIDs of mails and then create RDOMail object here in
> secondary thread.

> Lets say I do as I said above. How should i release RDOMails created in
> main
> thread? (RDOMails are required in main thread as well since we set some
> user
> property there)

> Please advise.

> "Dmitry Streblechenko" wrote:
>
> > All threads that use Extended MAPI must call MAPIInitialize. Outlook
> > calls
> > it on its main thread, but if you create your own secondary thread, that
> > is
> > your responsibility.
> > All creatable Redemption objects (including RDOSession) do that. Try to
> > create an instance of the RDOSession object on the secondary thread, sets
> > its MAPIOBJECT property to Application.Session.MAPIOBJECT from Outlook to
> > make sure the two share the same MAPI sessio, then retrieve RDOMail.
> > > > Dmitry Streblechenko (MVP)
> >

> >

> >

> > -
> > "Sandeep K" <SandeepK> wrote in message
> > news:21FA0EB2-903C-469E-9CD8-D9952FBA28A8@microsoft.com...
> > > Hi Ken,
> > > The problem here is getting the information back from the background
> > > worker
> > > thread. My scenario is like this:
> > > I do some processing based on the content of email and then based on
> > > the
> > > result I update the mail object properties. As I am using a background
> > > workder thread for processing email content, I can now pass the email
> > > content
> > > directly to the background worker. Now as background worker thread can
> > > not
> > > access mail object, I believe I need the processing results to be
> > > passed
> > > back
> > > to Main thread. Is there a way to pass the result back to main thread
> > > so
> > > that
> > > It can set properties of the emails.
> >> > " - " wrote:
> >> >> Sure. Set up the code to run with server side MAPI on a machine that
> > >> never
> > >> has had Outlook installed.
> > >
>> >> What you want won't work. It will hang or crash Outlook and/or your
> > >> addin
> > >> code. Think of a different method such as getting the information in
> > >> the
> > >> foreground thread and then passing strings or whatever to the
> > >> background
> > >> thread. Otherwise you're just causing yourself plus any other code
> > >> running
> > >> on that machine nothing but headaches.
> > >
>> >> > > >>

> > >>

> > >
>> >
>> >
>> >
>> >
>> >
>> >> "Sandeep K" <SandeepK> wrote in message
> > >> news:B8E2F05E-56EC-4B71-B263-B2CCA4F7E6F8@microsoft.com...
> > >> > Hi,
> > >> > I am using RDOMail object to retrieve email data and setting user
> > >> > properties. RDOMail object works fine in the main thread, 'ThisAddin
> > >> > thread',
> > >> > (I am creating VSTO Add-in) but when I use same RDOObject in the
> > >> > worker
> > >> > thread all function calls on the RDOMail object in debugger
> > >> > evaluates
> > >> > to
> > >> > error "Function evaluation disabled because a previous function
> > >> > evaluation
> > >> > timed out. You must continue execution to reenable function
> > >> > evaluation.".
> > >>> >> > Any clue how can i use RDOMail object in worker thread which is
> > >> > different
> > >> > thread than ThisAddin thread.
> > >
>> >>

>

>
>>
 
D

Dmitry Streblechenko

In your second example, can you access any properties in teh code rather

than in the debugger?

string Subject = rmail.Subject;

Can you see the value of the Subject variable?

Dmitry Streblechenko (MVP)

-

"Sandeep K" <SandeepK> wrote in message

news:3AAC4CC8-94D3-42B1-9160-BB4DAB78A8C0@microsoft.com...
> I tried following two code segment in secondary thread but niether is
> working. RDOMail evaluates to same error.

> RDOSession rsession = new RDOSessionClass();
> Outlook.Application app = new Outlook.ApplicationClass();
> rsession.MAPIOBJECT = app.Session.MAPIOBJECT;
> ArrayList rmails = new ArrayList();
> foreach (string entryId in maillist)
> {
> RDOMail rmail = rsession.GetMessageFromID(entryId,
> System.Reflection.Missing.Value, System.Reflection.Missing.Value);

> rmails.Add(rmail);
> }

> or
> RDOSession rsession = new RDOSessionClass();
> rsession.MAPIOBJECT = Globals.AddinMain.Application.Session.MAPIOBJECT;
> foreach (string entryId in maillist)
> {
> RDOMail rmail = rsession.GetMessageFromID(entryId,
> System.Reflection.Missing.Value, System.Reflection.Missing.Value);

> rmails.Add(rmail);
> }

> please advise.

> "Dmitry Streblechenko" wrote:
>
> > All threads that use Extended MAPI must call MAPIInitialize. Outlook
> > calls
> > it on its main thread, but if you create your own secondary thread, that
> > is
> > your responsibility.
> > All creatable Redemption objects (including RDOSession) do that. Try to
> > create an instance of the RDOSession object on the secondary thread, sets
> > its MAPIOBJECT property to Application.Session.MAPIOBJECT from Outlook to
> > make sure the two share the same MAPI sessio, then retrieve RDOMail.
> > > > Dmitry Streblechenko (MVP)
> >

> >

> >

> > -
> > "Sandeep K" <SandeepK> wrote in message
> > news:21FA0EB2-903C-469E-9CD8-D9952FBA28A8@microsoft.com...
> > > Hi Ken,
> > > The problem here is getting the information back from the background
> > > worker
> > > thread. My scenario is like this:
> > > I do some processing based on the content of email and then based on
> > > the
> > > result I update the mail object properties. As I am using a background
> > > workder thread for processing email content, I can now pass the email
> > > content
> > > directly to the background worker. Now as background worker thread can
> > > not
> > > access mail object, I believe I need the processing results to be
> > > passed
> > > back
> > > to Main thread. Is there a way to pass the result back to main thread
> > > so
> > > that
> > > It can set properties of the emails.
> >> > " - " wrote:
> >> >> Sure. Set up the code to run with server side MAPI on a machine that
> > >> never
> > >> has had Outlook installed.
> > >
>> >> What you want won't work. It will hang or crash Outlook and/or your
> > >> addin
> > >> code. Think of a different method such as getting the information in
> > >> the
> > >> foreground thread and then passing strings or whatever to the
> > >> background
> > >> thread. Otherwise you're just causing yourself plus any other code
> > >> running
> > >> on that machine nothing but headaches.
> > >
>> >> > > >>

> > >>

> > >
>> >
>> >
>> >
>> >
>> >
>> >> "Sandeep K" <SandeepK> wrote in message
> > >> news:B8E2F05E-56EC-4B71-B263-B2CCA4F7E6F8@microsoft.com...
> > >> > Hi,
> > >> > I am using RDOMail object to retrieve email data and setting user
> > >> > properties. RDOMail object works fine in the main thread, 'ThisAddin
> > >> > thread',
> > >> > (I am creating VSTO Add-in) but when I use same RDOObject in the
> > >> > worker
> > >> > thread all function calls on the RDOMail object in debugger
> > >> > evaluates
> > >> > to
> > >> > error "Function evaluation disabled because a previous function
> > >> > evaluation
> > >> > timed out. You must continue execution to reenable function
> > >> > evaluation.".
> > >>> >> > Any clue how can i use RDOMail object in worker thread which is
> > >> > different
> > >> > thread than ThisAddin thread.
> > >
>> >>

>

>
>>
 
S

Sandeep K

After reading some blogs on net. I am in agreement with ken not to do

anything related to mails object in other than main thread hence i have

created one Backgroundworker component in which i do long task in dowork()

event and I update RDOMails object in ProgressChanged and RunWorkerCompleted

event. Dowork eventhandler is secondary thread and code in ProgressChanged

and RunWorkerCompleted event handler executes in main thread. Now i do not

see any debugger errors. Though I am setting them in Progresschanged event

and saving email on RunWorkerCompleted event, I can not see user porperties

value in explorer view. Any clue?

Code example:

//Initialize the backgroundworker and RDOSession object. This code executes

in mainthread.

static MailSubmission()

{

backgroundWorker1 = new System.ComponentModel.BackgroundWorker();

InitializeBackgroundWorker();

rsession = new RDOSessionClass();

rsession.MAPIOBJECT =

Globals.AddinMain.Application.Session.MAPIOBJECT;

}

//Code executes in main thread

private static void backgroundWorker1_RunWorkerCompleted(

object sender, RunWorkerCompletedEventArgs e)

{

string entryId = (string)e.Result;

RDOMail rmail = rsession.GetMessageFromID(entryId,

System.Reflection.Missing.Value, System.Reflection.Missing.Value);

rmail.Save();

}

private static void backgroundWorker1_ProgressChanged(object sender,

ProgressChangedEventArgs e)

{

string entryId = (string)e.UserState;

RDOMail rmail = rsession.GetMessageFromID(entryId,

System.Reflection.Missing.Value, System.Reflection.Missing.Value);

RDOUserProperty prop = rmail.UserProperties.Find(someproperty, true);

prop.value = "something";

}

//Code executes in secondary thread

private static void backgroundWorker1_DoWork(object sender,

DoWorkEventArgs e)

{

string emailEntryId= (string)e.Argument;

// Get the BackgroundWorker that raised this event.

BackgroundWorker worker = sender as BackgroundWorker;

Thread.Sleep(1000);

worker.ReportProgress(33, userstate);

Thread.Sleep(1000);

worker.ReportProgress(66, userstate);

Thread.Sleep(1000);

e.Result = emailEntryId;

}

"Dmitry Streblechenko" wrote:


> In your second example, can you access any properties in teh code rather
> than in the debugger?

> string Subject = rmail.Subject;

> Can you see the value of the Subject variable?

> > Dmitry Streblechenko (MVP)
>

>

>

> -
> "Sandeep K" <SandeepK> wrote in message
> news:3AAC4CC8-94D3-42B1-9160-BB4DAB78A8C0@microsoft.com...
> >I tried following two code segment in secondary thread but niether is
> > working. RDOMail evaluates to same error.
> > RDOSession rsession = new RDOSessionClass();
> > Outlook.Application app = new Outlook.ApplicationClass();
> > rsession.MAPIOBJECT = app.Session.MAPIOBJECT;
> > ArrayList rmails = new ArrayList();
> > foreach (string entryId in maillist)
> > {
> > RDOMail rmail = rsession.GetMessageFromID(entryId,
> > System.Reflection.Missing.Value, System.Reflection.Missing.Value);
> > rmails.Add(rmail);
> > }
> > or
> > RDOSession rsession = new RDOSessionClass();
> > rsession.MAPIOBJECT = Globals.AddinMain.Application.Session.MAPIOBJECT;
> > foreach (string entryId in maillist)
> > {
> > RDOMail rmail = rsession.GetMessageFromID(entryId,
> > System.Reflection.Missing.Value, System.Reflection.Missing.Value);
> > rmails.Add(rmail);
> > }
> > please advise.
> > "Dmitry Streblechenko" wrote:
> >
> >> All threads that use Extended MAPI must call MAPIInitialize. Outlook
> >> calls
> >> it on its main thread, but if you create your own secondary thread, that
> >> is
> >> your responsibility.
> >> All creatable Redemption objects (including RDOSession) do that. Try to
> >> create an instance of the RDOSession object on the secondary thread, sets
> >> its MAPIOBJECT property to Application.Session.MAPIOBJECT from Outlook to
> >> make sure the two share the same MAPI sessio, then retrieve RDOMail.
> >> > >> Dmitry Streblechenko (MVP)
> >>

> >>

> >>

> >> -
> >> "Sandeep K" <SandeepK> wrote in message
> >> news:21FA0EB2-903C-469E-9CD8-D9952FBA28A8@microsoft.com...
> >> > Hi Ken,
> >> > The problem here is getting the information back from the background
> >> > worker
> >> > thread. My scenario is like this:
> >> > I do some processing based on the content of email and then based on
> >> > the
> >> > result I update the mail object properties. As I am using a background
> >> > workder thread for processing email content, I can now pass the email
> >> > content
> >> > directly to the background worker. Now as background worker thread can
> >> > not
> >> > access mail object, I believe I need the processing results to be
> >> > passed
> >> > back
> >> > to Main thread. Is there a way to pass the result back to main thread
> >> > so
> >> > that
> >> > It can set properties of the emails.
> >> >> > " - " wrote:
> >> >> >> Sure. Set up the code to run with server side MAPI on a machine that
> >> >> never
> >> >> has had Outlook installed.
> >> >
> >> >> What you want won't work. It will hang or crash Outlook and/or your
> >> >> addin
> >> >> code. Think of a different method such as getting the information in
> >> >> the
> >> >> foreground thread and then passing strings or whatever to the
> >> >> background
> >> >> thread. Otherwise you're just causing yourself plus any other code
> >> >> running
> >> >> on that machine nothing but headaches.
> >> >
> >> >> > >> >>

> >> >>

> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >> "Sandeep K" <SandeepK> wrote in message
> >> >> news:B8E2F05E-56EC-4B71-B263-B2CCA4F7E6F8@microsoft.com...
> >> >> > Hi,
> >> >> > I am using RDOMail object to retrieve email data and setting user
> >> >> > properties. RDOMail object works fine in the main thread, 'ThisAddin
> >> >> > thread',
> >> >> > (I am creating VSTO Add-in) but when I use same RDOObject in the
> >> >> > worker
> >> >> > thread all function calls on the RDOMail object in debugger
> >> >> > evaluates
> >> >> > to
> >> >> > error "Function evaluation disabled because a previous function
> >> >> > evaluation
> >> >> > timed out. You must continue execution to reenable function
> >> >> > evaluation.".
> >> >> >> >> > Any clue how can i use RDOMail object in worker thread which is
> >> >> > different
> >> >> > thread than ThisAddin thread.
> >> >
> >> >
> >
> >
> >>


>
 
K

Ken Slovak - [MVP - Outlook]

Are you saving the RDOMail item? Do you see the value in the Explorer if you

change folders and back again or stop and restart Outlook?

You might have to tell Outlook something has changed since it won't reflect

changes at the MAPI level otherwise. Usually we use something like this to

tell Outlook something has changed: item.Subject = item.Subject, then we

save the item.

"Sandeep K" <SandeepK> wrote in message

news:49942380-1106-40EE-B1BA-859EFCB921BA@microsoft.com...
> After reading some blogs on net. I am in agreement with ken not to do
> anything related to mails object in other than main thread hence i have
> created one Backgroundworker component in which i do long task in dowork()
> event and I update RDOMails object in ProgressChanged and
> RunWorkerCompleted
> event. Dowork eventhandler is secondary thread and code in ProgressChanged
> and RunWorkerCompleted event handler executes in main thread. Now i do not
> see any debugger errors. Though I am setting them in Progresschanged event
> and saving email on RunWorkerCompleted event, I can not see user
> porperties
> value in explorer view. Any clue?

> Code example:
> //Initialize the backgroundworker and RDOSession object. This code
> executes
> in mainthread.
> static MailSubmission()
> {
> backgroundWorker1 = new
> System.ComponentModel.BackgroundWorker();
> InitializeBackgroundWorker();
> rsession = new RDOSessionClass();
> rsession.MAPIOBJECT =
> Globals.AddinMain.Application.Session.MAPIOBJECT;
> }
> //Code executes in main thread
> private static void backgroundWorker1_RunWorkerCompleted(
> object sender, RunWorkerCompletedEventArgs e)
> {

> string entryId = (string)e.Result;
> RDOMail rmail = rsession.GetMessageFromID(entryId,
> System.Reflection.Missing.Value, System.Reflection.Missing.Value);
> rmail.Save();
> }

> private static void backgroundWorker1_ProgressChanged(object
> sender,
> ProgressChangedEventArgs e)
> {
> string entryId = (string)e.UserState;
> RDOMail rmail = rsession.GetMessageFromID(entryId,
> System.Reflection.Missing.Value, System.Reflection.Missing.Value);
> RDOUserProperty prop = rmail.UserProperties.Find(someproperty, true);
> prop.value = "something";
> }
> //Code executes in secondary thread
> private static void backgroundWorker1_DoWork(object sender,
> DoWorkEventArgs e)
> {
> string emailEntryId= (string)e.Argument;
> // Get the BackgroundWorker that raised this event.
> BackgroundWorker worker = sender as BackgroundWorker;
> Thread.Sleep(1000);
> worker.ReportProgress(33, userstate);
> Thread.Sleep(1000);
> worker.ReportProgress(66, userstate);
> Thread.Sleep(1000);
> e.Result = emailEntryId;
> }

>
 
D

Dmitry Streblechenko

And also why are you saving teh mesasge immediately after callign

GetMessageFromID? You need to save it after after you make changes.

Dmitry Streblechenko (MVP)

-
<kenslovak@mvps.org> wrote in message

news:uqL0knwMKHA.1280@TK2MSFTNGP04.phx.gbl...
> Are you saving the RDOMail item? Do you see the value in the Explorer if
> you change folders and back again or stop and restart Outlook?

> You might have to tell Outlook something has changed since it won't
> reflect changes at the MAPI level otherwise. Usually we use something like
> this to tell Outlook something has changed: item.Subject = item.Subject,
> then we save the item.

> >

>

> "Sandeep K" <SandeepK> wrote in message
> news:49942380-1106-40EE-B1BA-859EFCB921BA@microsoft.com...
> > After reading some blogs on net. I am in agreement with ken not to do
> > anything related to mails object in other than main thread hence i have
> > created one Backgroundworker component in which i do long task in
> > dowork()
> > event and I update RDOMails object in ProgressChanged and
> > RunWorkerCompleted
> > event. Dowork eventhandler is secondary thread and code in
> > ProgressChanged
> > and RunWorkerCompleted event handler executes in main thread. Now i do
> > not
> > see any debugger errors. Though I am setting them in Progresschanged
> > event
> > and saving email on RunWorkerCompleted event, I can not see user
> > porperties
> > value in explorer view. Any clue?
>

>> Code example:
> > //Initialize the backgroundworker and RDOSession object. This code
> > executes
> > in mainthread.
> > static MailSubmission()
> > {
> > backgroundWorker1 = new
> > System.ComponentModel.BackgroundWorker();
> > InitializeBackgroundWorker();
> > rsession = new RDOSessionClass();
> > rsession.MAPIOBJECT =
> > Globals.AddinMain.Application.Session.MAPIOBJECT;
> > }
> > //Code executes in main thread
> > private static void backgroundWorker1_RunWorkerCompleted(
> > object sender, RunWorkerCompletedEventArgs e)
> > {
>

>> string entryId = (string)e.Result;
> > RDOMail rmail = rsession.GetMessageFromID(entryId,
> > System.Reflection.Missing.Value, System.Reflection.Missing.Value);
> > rmail.Save();
> > }
>

>> private static void backgroundWorker1_ProgressChanged(object
> > sender,
> > ProgressChangedEventArgs e)
> > {
> > string entryId = (string)e.UserState;
> > RDOMail rmail = rsession.GetMessageFromID(entryId,
> > System.Reflection.Missing.Value, System.Reflection.Missing.Value);
> > RDOUserProperty prop = rmail.UserProperties.Find(someproperty, true);
> > prop.value = "something";
> > }
> > //Code executes in secondary thread
> > private static void backgroundWorker1_DoWork(object sender,
> > DoWorkEventArgs e)
> > {
> > string emailEntryId= (string)e.Argument;
> > // Get the BackgroundWorker that raised this event.
> > BackgroundWorker worker = sender as BackgroundWorker;
> > Thread.Sleep(1000);
> > worker.ReportProgress(33, userstate);
> > Thread.Sleep(1000);
> > worker.ReportProgress(66, userstate);
> > Thread.Sleep(1000);
> > e.Result = emailEntryId;
> > }
>

>>

>
 
S

Sandeep K

Thanks a lot things are now working for me.
wrote:


> Are you saving the RDOMail item? Do you see the value in the Explorer if you
> change folders and back again or stop and restart Outlook?

> You might have to tell Outlook something has changed since it won't reflect
> changes at the MAPI level otherwise. Usually we use something like this to
> tell Outlook something has changed: item.Subject = item.Subject, then we
> save the item.

> >

>

> "Sandeep K" <SandeepK> wrote in message
> news:49942380-1106-40EE-B1BA-859EFCB921BA@microsoft.com...
> > After reading some blogs on net. I am in agreement with ken not to do
> > anything related to mails object in other than main thread hence i have
> > created one Backgroundworker component in which i do long task in dowork()
> > event and I update RDOMails object in ProgressChanged and
> > RunWorkerCompleted
> > event. Dowork eventhandler is secondary thread and code in ProgressChanged
> > and RunWorkerCompleted event handler executes in main thread. Now i do not
> > see any debugger errors. Though I am setting them in Progresschanged event
> > and saving email on RunWorkerCompleted event, I can not see user
> > porperties
> > value in explorer view. Any clue?
> > Code example:
> > //Initialize the backgroundworker and RDOSession object. This code
> > executes
> > in mainthread.
> > static MailSubmission()
> > {
> > backgroundWorker1 = new
> > System.ComponentModel.BackgroundWorker();
> > InitializeBackgroundWorker();
> > rsession = new RDOSessionClass();
> > rsession.MAPIOBJECT =
> > Globals.AddinMain.Application.Session.MAPIOBJECT;
> > }
> > //Code executes in main thread
> > private static void backgroundWorker1_RunWorkerCompleted(
> > object sender, RunWorkerCompletedEventArgs e)
> > {
> > string entryId = (string)e.Result;
> > RDOMail rmail = rsession.GetMessageFromID(entryId,
> > System.Reflection.Missing.Value, System.Reflection.Missing.Value);
> > rmail.Save();
> > }
> > private static void backgroundWorker1_ProgressChanged(object
> > sender,
> > ProgressChangedEventArgs e)
> > {
> > string entryId = (string)e.UserState;
> > RDOMail rmail = rsession.GetMessageFromID(entryId,
> > System.Reflection.Missing.Value, System.Reflection.Missing.Value);
> > RDOUserProperty prop = rmail.UserProperties.Find(someproperty, true);
> > prop.value = "something";
> > }
> > //Code executes in secondary thread
> > private static void backgroundWorker1_DoWork(object sender,
> > DoWorkEventArgs e)
> > {
> > string emailEntryId= (string)e.Argument;
> > // Get the BackgroundWorker that raised this event.
> > BackgroundWorker worker = sender as BackgroundWorker;
> > Thread.Sleep(1000);
> > worker.ReportProgress(33, userstate);
> > Thread.Sleep(1000);
> > worker.ReportProgress(66, userstate);
> > Thread.Sleep(1000);
> > e.Result = emailEntryId;
> > }
> >


>
 
S

Sandeep K

Thanks a lot things are now working for me.

"Dmitry Streblechenko" wrote:


> And also why are you saving teh mesasge immediately after callign
> GetMessageFromID? You need to save it after after you make changes.

> > Dmitry Streblechenko (MVP)
>

>

>

> -
> " - " <kenslovak@mvps.org> wrote in message
> news:uqL0knwMKHA.1280@TK2MSFTNGP04.phx.gbl...
> > Are you saving the RDOMail item? Do you see the value in the Explorer if
> > you change folders and back again or stop and restart Outlook?
> > You might have to tell Outlook something has changed since it won't
> > reflect changes at the MAPI level otherwise. Usually we use something like
> > this to tell Outlook something has changed: item.Subject = item.Subject,
> > then we save the item.
> > > >

> >

> > "Sandeep K" <SandeepK> wrote in message
> > news:49942380-1106-40EE-B1BA-859EFCB921BA@microsoft.com...
> >> After reading some blogs on net. I am in agreement with ken not to do
> >> anything related to mails object in other than main thread hence i have
> >> created one Backgroundworker component in which i do long task in
> >> dowork()
> >> event and I update RDOMails object in ProgressChanged and
> >> RunWorkerCompleted
> >> event. Dowork eventhandler is secondary thread and code in
> >> ProgressChanged
> >> and RunWorkerCompleted event handler executes in main thread. Now i do
> >> not
> >> see any debugger errors. Though I am setting them in Progresschanged
> >> event
> >> and saving email on RunWorkerCompleted event, I can not see user
> >> porperties
> >> value in explorer view. Any clue?
> >
> >> Code example:
> >> //Initialize the backgroundworker and RDOSession object. This code
> >> executes
> >> in mainthread.
> >> static MailSubmission()
> >> {
> >> backgroundWorker1 = new
> >> System.ComponentModel.BackgroundWorker();
> >> InitializeBackgroundWorker();
> >> rsession = new RDOSessionClass();
> >> rsession.MAPIOBJECT =
> >> Globals.AddinMain.Application.Session.MAPIOBJECT;
> >> }
> >> //Code executes in main thread
> >> private static void backgroundWorker1_RunWorkerCompleted(
> >> object sender, RunWorkerCompletedEventArgs e)
> >> {
> >
> >> string entryId = (string)e.Result;
> >> RDOMail rmail = rsession.GetMessageFromID(entryId,
> >> System.Reflection.Missing.Value, System.Reflection.Missing.Value);
> >> rmail.Save();
> >> }
> >
> >> private static void backgroundWorker1_ProgressChanged(object
> >> sender,
> >> ProgressChangedEventArgs e)
> >> {
> >> string entryId = (string)e.UserState;
> >> RDOMail rmail = rsession.GetMessageFromID(entryId,
> >> System.Reflection.Missing.Value, System.Reflection.Missing.Value);
> >> RDOUserProperty prop = rmail.UserProperties.Find(someproperty, true);
> >> prop.value = "something";
> >> }
> >> //Code executes in secondary thread
> >> private static void backgroundWorker1_DoWork(object sender,
> >> DoWorkEventArgs e)
> >> {
> >> string emailEntryId= (string)e.Argument;
> >> // Get the BackgroundWorker that raised this event.
> >> BackgroundWorker worker = sender as BackgroundWorker;
> >> Thread.Sleep(1000);
> >> worker.ReportProgress(33, userstate);
> >> Thread.Sleep(1000);
> >> worker.ReportProgress(66, userstate);
> >> Thread.Sleep(1000);
> >> e.Result = emailEntryId;
> >> }
> >
> >>

> >


>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
W Redemption::RDOMail.PrintOut() / DoAction(maPrint) not working Outlook VBA and Custom Forms 1
R How to get the Items object of the default mailbox of a specific account in a multiple account Outlook? Outlook VBA and Custom Forms 0
A Run time error 424. object required in outlook 2013 Outlook VBA and Custom Forms 10
vodkasoda Object could not be found Error in Outlook 2007 Outlook VBA and Custom Forms 5
S VBA Macro - Run-time error '424': object required - Help Please Outlook VBA and Custom Forms 3
P Automate Outlook Start - No Active Explorer Object Found Using Outlook 10
J Object Variable or With Block Not Set Error in Outlook 2016 and not Outlook 2013 Outlook VBA and Custom Forms 3
R Macro to copy email to excel - Runtime Error 91 Object Variable Not Set Outlook VBA and Custom Forms 11
J Outlook 2016 is killing me with object.links Outlook VBA and Custom Forms 2
S how to access the properties of a contact given distlist.member object Outlook VBA and Custom Forms 1
J An attempt operation failed. An object could not be found at line5. Outlook VBA and Custom Forms 2
R How can I retain embedded object with voting button reply? Using Outlook 5
G run-time 438: object doesn't support this property or method Using Outlook 2
B Task List in To-Do Bar 'The operation failed. An object could not be found' Using Outlook 3
A vb6 run time error 5 when Outlook 2007 Explorer object displayed Outlook VBA and Custom Forms 1
P Problem with a Search-Object resulting from an AdvancedSearch Outlook VBA and Custom Forms 2
T How to get Inspector object from Window handle Outlook VBA and Custom Forms 2
M MailItem object has no property for when a reply was sent Outlook VBA and Custom Forms 3
T Complete the object model Outlook Wishlist 0
M Outlook Contact Object: Is there a "last accessed" date-time prope Outlook VBA and Custom Forms 3
M Cannot Send - "Operation failed. An object cannot be found" BCM (Business Contact Manager) 4
K How to disconnect Application.COMAddIns.Item().Object? Outlook VBA and Custom Forms 4
G Error in Outlook Object Model with redemption and google apps prem Outlook VBA and Custom Forms 3
C Unable to cast object of type 'System.Int32' to type 'System.Byte[ BCM (Business Contact Manager) 1
S UserProperties of MailItem object. Outlook VBA and Custom Forms 3
P UserProperty of mail object problem while dealing with custom fold Outlook VBA and Custom Forms 2
J object that has been separated from its underlying RCW Outlook VBA and Custom Forms 11
S How to get RFC822 format message from the MailItem object. Outlook VBA and Custom Forms 4
B Compile error: Object required Outlook VBA and Custom Forms 2
S Strange Behaviour of Explorer Object. Outlook VBA and Custom Forms 1
R Unable to cast COM object" error Outlook VBA and Custom Forms 2
R Unable to cast COM object" error Outlook VBA and Custom Forms 5
R destroying Explorer object pointers on shutdown Outlook VBA and Custom Forms 2
T COM object that has been separated from its underlying RCW Outlook VBA and Custom Forms 1
G print attachment straight away; working script edit not working Outlook VBA and Custom Forms 0
V Auto-complete stopped working Using Outlook 4
F Searches are not working properly Using Outlook 1
Jennifer Murphy Spam filter not working Using Outlook 13
D Connecting Gmail to Outlook 365 - My Setup not working Using Outlook 2
A Prepending Email Addrs with "Display Name <email>" Has Stopped Working Using Outlook 0
R rules not working - done troubleshooting Using Outlook 0
R Follow up button doesn't working neither the reminders in BCM BCM (Business Contact Manager) 0
A calendar invites sent from Microsoft Outlook to Mac Outlook is not working Using Outlook 2
B Task Filter Not Working When I add too many criteria Using Outlook 0
D iCloud Add-in not working in Outlook 2013 and Outlook 2016 After Windows Upgrade & iCloud Upgrade Using Outlook 2
bmtjedi Set objApp = Application Not Working in O365-32bit Using Outlook 1
B Outlook 2003 email sending & receiving suddenly stopped working Using Outlook 3
S Outlook Custom Form Scripting only working when clicking on "Run this form" Outlook VBA and Custom Forms 2
K Outlook 2016 - controlling IMAP OST size with Group Policy not working Using Outlook 1
F KB4475563 stops VBS at forms working Outlook VBA and Custom Forms 3

Similar threads

Top