473,734 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BackGroundWorke r.ProgressChang ed "Cross-thread operation not valid" at 2nd/3th/... progress

Hi,

I'm having some weird problem using the BackGroundWorke r in an Outlook
(2003) Add-In, with VB.NET 2005:
I'm using the BackGroundWorke r to get the info of some mailitems, and after
each item I want to raise the ProgressChanged-event to update the
DataGridView.
It works fine when only one Progresschanged is fired, but at the second,
third, fopurth etc it raises everytile a 'Cross-thread operation not
valid"-exception on lmy DataGridView (dgvAdd).

Any idea what causes this problem? What am I doing wrong? What is the
problem here?

Any help our hints would be really appreciated!

Thanks a lot in advance,

Pieter
This is my code:
Me.bgwInfoOutlo ok.RunWorkerAsy nc(Me.m_colItem s)

Private Sub bgwInfoOutlook_ DoWork(ByVal sender As Object, ByVal e As
System.Componen tModel.DoWorkEv entArgs) Handles bgwInfoOutlook. DoWork
Dim col As Collection = e.Argument
AddHandler docCtrl.InfoLis tChanged, AddressOf InfoListChanged
Dim str As String = docCtrl.GetOutl ookInfo(col,
Me.m_objOutlook Folder)
e.Result = docCtrl.AddedDo cMails
End Sub

Private Sub InfoListChanged (ByVal sender As Object, ByVal e As
EventArgs)
Me.bgwInfoOutlo ok.ReportProgre ss(0)
End Sub

Private Sub bgwInfoOutlook_ ProgressChanged (ByVal sender As Object, ByVal
e As System.Componen tModel.Progress ChangedEventArg s) Handles
bgwInfoOutlook. ProgressChanged
'bind the list to the datagridview
Try
Me.dgvAdd.DataS ource = Nothing
Me.dgvAdd.DataS ource = docCtrl.InfoLis t
Catch ex As Exception
ErrorMessage(ex )
End Try
End Sub
This is the exception:

{"Cross-thread operation not valid: Control 'dgvAdd' accessed from a thread
other than the thread it was created on."}
System.InvalidO perationExcepti on: {"Cross-thread operation not valid:
Control 'dgvAdd' accessed from a thread other than the thread it was created
on."}
Data: {System.Collect ions.ListDictio naryInternal}
HelpLink: Nothing
InnerException: Nothing
Message: "Cross-thread operation not valid: Control 'dgvAdd' accessed
from a thread other than the thread it was created on."
Source: "System.Windows .Forms"
StackTrace: " at System.Windows. Forms.Control.g et_Handle()
at System.Windows. Forms.Control.g et_InternalHand le()
at System.Windows. Forms.Control.g et_CreateParams ()
at System.Windows. Forms.ScrollBar .get_CreatePara ms()
at System.Windows. Forms.VScrollBa r.get_CreatePar ams()
at System.Windows. Forms.Control.U pdateBounds(Int 32 x, Int32 y, Int32
width, Int32 height)
at System.Windows. Forms.Control.S etBoundsCore(In t32 x, Int32 y, Int32
width, Int32 height, BoundsSpecified specified)
at System.Windows. Forms.Control.S etBounds(Int32 x, Int32 y, Int32 width,
Int32 height, BoundsSpecified specified)
at System.Windows. Forms.Control.s et_Bounds(Recta ngle value)
at System.Windows. Forms.DataGridV iew.LayoutScrol lBars()
at System.Windows. Forms.DataGridV iew.ComputeLayo ut()
at System.Windows. Forms.DataGridV iew.PerformLayo utPrivate(Boole an
useRowShortcut, Boolean computeVisibleR ows, Boolean
invalidInAdjust FillingColumns, Boolean repositionEditi ngControl)
at
System.Windows. Forms.DataGridV iew.OnColumnWid thChanged(DataG ridViewColumnEv entArgs
e)
at
System.Windows. Forms.DataGridV iew.OnBandThick nessChanged(Dat aGridViewBand
dataGridViewBan d)
at System.Windows. Forms.DataGridV iewBand.set_Thi cknessInternal( Int32
value)
at System.Windows. Forms.DataGridV iew.AdjustFilli ngColumns()
at System.Windows. Forms.DataGridV iew.ComputeLayo ut()
at System.Windows. Forms.DataGridV iew.PerformLayo utPrivate(Boole an
useRowShortcut, Boolean computeVisibleR ows, Boolean
invalidInAdjust FillingColumns, Boolean repositionEditi ngControl)
at System.Windows. Forms.DataGridV iew.ResetUIStat e(Boolean useRowShortcut,
Boolean computeVisibleR ows)
at
System.Windows. Forms.DataGridV iewRowCollectio n.OnCollectionC hanged_PreNotif ication(Collect ionChangeAction
cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow & dataGridViewRow ,
Boolean changeIsInserti on)
at
System.Windows. Forms.DataGridV iewRowCollectio n.OnCollectionC hanged(Collecti onChangeEventAr gs
e, Int32 rowIndex, Int32 rowCount, Boolean changeIsDeletio n, Boolean
changeIsInserti on, Boolean recreateNewRow, Point newCurrentCell)
at System.Windows. Forms.DataGridV iewRowCollectio n.InsertInterna l(Int32
rowIndex, DataGridViewRow dataGridViewRow , Boolean force)
at
System.Windows. Forms.DataGridV iew.DataGridVie wDataConnection .ProcessListCha nged(ListChange dEventArgs
e)
at
System.Windows. Forms.DataGridV iew.DataGridVie wDataConnection .currencyManage r_ListChanged(O bject
sender, ListChangedEven tArgs e)
at
System.Windows. Forms.CurrencyM anager.OnListCh anged(ListChang edEventArgs e)
at System.Windows. Forms.CurrencyM anager.List_Lis tChanged(Object sender,
ListChangedEven tArgs e)
at System.Componen tModel.BindingL ist`1.OnListCha nged(ListChange dEventArgs
e)
at System.Componen tModel.BindingL ist`1.FireListC hanged(ListChan gedType
type, Int32 index)
at System.Componen tModel.BindingL ist`1.InsertIte m(Int32 index, T item)
at System.Collecti ons.ObjectModel .Collection`1.A dd(T item)
at BaseFramework.c lsBaseList`1.Ad d(T item) in D:\NET Projecten\Code
Source Sodimex - Ghost\BaseFrame work\clsBaseLis t.vb:line 461
at DocControl.clsD ocControl.GetOu tlookInfo(Colle ction colItems, Object
oFolder, Boolean blnAttachments) in D:\NET Projecten\Code Source Sodimex -
Ghost\DocContro l\Business Layer\clsDocCon trol.vb:line 597"
TargetSite: {System.Reflect ion.RuntimeMeth odInfo}
Feb 13 '06 #1
8 4854
Hi Pieter,

As far as I know, .NET 2.0 strictly prohibits any access to the user
interface from background worker threads. This wasn't allowed in .NET 1.1
either, but in that version one sometimes could get away with violating the
rule. Now you'll get the "Cross-thread operation not valid" almost for sure.

Therefore, to do any updates to the UI properly, you should use the
Control.Invoke method to run the UI update code on the UI thread.

"Pieter" <pi**********@h otmail.com> wrote in message
news:eU******** *******@tk2msft ngp13.phx.gbl.. .
Hi,

I'm having some weird problem using the BackGroundWorke r in an Outlook
(2003) Add-In, with VB.NET 2005:
I'm using the BackGroundWorke r to get the info of some mailitems, and
after each item I want to raise the ProgressChanged-event to update the
DataGridView.
It works fine when only one Progresschanged is fired, but at the second,
third, fopurth etc it raises everytile a 'Cross-thread operation not
valid"-exception on lmy DataGridView (dgvAdd).

Any idea what causes this problem? What am I doing wrong? What is the
problem here?

Any help our hints would be really appreciated!

Thanks a lot in advance,

Pieter
This is my code:
Me.bgwInfoOutlo ok.RunWorkerAsy nc(Me.m_colItem s)

Private Sub bgwInfoOutlook_ DoWork(ByVal sender As Object, ByVal e As
System.Componen tModel.DoWorkEv entArgs) Handles bgwInfoOutlook. DoWork
Dim col As Collection = e.Argument
AddHandler docCtrl.InfoLis tChanged, AddressOf InfoListChanged
Dim str As String = docCtrl.GetOutl ookInfo(col,
Me.m_objOutlook Folder)
e.Result = docCtrl.AddedDo cMails
End Sub

Private Sub InfoListChanged (ByVal sender As Object, ByVal e As
EventArgs)
Me.bgwInfoOutlo ok.ReportProgre ss(0)
End Sub

Private Sub bgwInfoOutlook_ ProgressChanged (ByVal sender As Object,
ByVal e As System.Componen tModel.Progress ChangedEventArg s) Handles
bgwInfoOutlook. ProgressChanged
'bind the list to the datagridview
Try
Me.dgvAdd.DataS ource = Nothing
Me.dgvAdd.DataS ource = docCtrl.InfoLis t
Catch ex As Exception
ErrorMessage(ex )
End Try
End Sub
This is the exception:

{"Cross-thread operation not valid: Control 'dgvAdd' accessed from a
thread other than the thread it was created on."}
System.InvalidO perationExcepti on: {"Cross-thread operation not valid:
Control 'dgvAdd' accessed from a thread other than the thread it was
created on."}
Data: {System.Collect ions.ListDictio naryInternal}
HelpLink: Nothing
InnerException: Nothing
Message: "Cross-thread operation not valid: Control 'dgvAdd' accessed
from a thread other than the thread it was created on."
Source: "System.Windows .Forms"
StackTrace: " at System.Windows. Forms.Control.g et_Handle()
at System.Windows. Forms.Control.g et_InternalHand le()
at System.Windows. Forms.Control.g et_CreateParams ()
at System.Windows. Forms.ScrollBar .get_CreatePara ms()
at System.Windows. Forms.VScrollBa r.get_CreatePar ams()
at System.Windows. Forms.Control.U pdateBounds(Int 32 x, Int32 y, Int32
width, Int32 height)
at System.Windows. Forms.Control.S etBoundsCore(In t32 x, Int32 y, Int32
width, Int32 height, BoundsSpecified specified)
at System.Windows. Forms.Control.S etBounds(Int32 x, Int32 y, Int32 width,
Int32 height, BoundsSpecified specified)
at System.Windows. Forms.Control.s et_Bounds(Recta ngle value)
at System.Windows. Forms.DataGridV iew.LayoutScrol lBars()
at System.Windows. Forms.DataGridV iew.ComputeLayo ut()
at System.Windows. Forms.DataGridV iew.PerformLayo utPrivate(Boole an
useRowShortcut, Boolean computeVisibleR ows, Boolean
invalidInAdjust FillingColumns, Boolean repositionEditi ngControl)
at
System.Windows. Forms.DataGridV iew.OnColumnWid thChanged(DataG ridViewColumnEv entArgs
e)
at
System.Windows. Forms.DataGridV iew.OnBandThick nessChanged(Dat aGridViewBand
dataGridViewBan d)
at System.Windows. Forms.DataGridV iewBand.set_Thi cknessInternal( Int32
value)
at System.Windows. Forms.DataGridV iew.AdjustFilli ngColumns()
at System.Windows. Forms.DataGridV iew.ComputeLayo ut()
at System.Windows. Forms.DataGridV iew.PerformLayo utPrivate(Boole an
useRowShortcut, Boolean computeVisibleR ows, Boolean
invalidInAdjust FillingColumns, Boolean repositionEditi ngControl)
at System.Windows. Forms.DataGridV iew.ResetUIStat e(Boolean
useRowShortcut, Boolean computeVisibleR ows)
at
System.Windows. Forms.DataGridV iewRowCollectio n.OnCollectionC hanged_PreNotif ication(Collect ionChangeAction
cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow & dataGridViewRow ,
Boolean changeIsInserti on)
at
System.Windows. Forms.DataGridV iewRowCollectio n.OnCollectionC hanged(Collecti onChangeEventAr gs
e, Int32 rowIndex, Int32 rowCount, Boolean changeIsDeletio n, Boolean
changeIsInserti on, Boolean recreateNewRow, Point newCurrentCell)
at System.Windows. Forms.DataGridV iewRowCollectio n.InsertInterna l(Int32
rowIndex, DataGridViewRow dataGridViewRow , Boolean force)
at
System.Windows. Forms.DataGridV iew.DataGridVie wDataConnection .ProcessListCha nged(ListChange dEventArgs
e)
at
System.Windows. Forms.DataGridV iew.DataGridVie wDataConnection .currencyManage r_ListChanged(O bject
sender, ListChangedEven tArgs e)
at
System.Windows. Forms.CurrencyM anager.OnListCh anged(ListChang edEventArgs e)
at System.Windows. Forms.CurrencyM anager.List_Lis tChanged(Object sender,
ListChangedEven tArgs e)
at
System.Componen tModel.BindingL ist`1.OnListCha nged(ListChange dEventArgs e)
at System.Componen tModel.BindingL ist`1.FireListC hanged(ListChan gedType
type, Int32 index)
at System.Componen tModel.BindingL ist`1.InsertIte m(Int32 index, T item)
at System.Collecti ons.ObjectModel .Collection`1.A dd(T item)
at BaseFramework.c lsBaseList`1.Ad d(T item) in D:\NET Projecten\Code
Source Sodimex - Ghost\BaseFrame work\clsBaseLis t.vb:line 461
at DocControl.clsD ocControl.GetOu tlookInfo(Colle ction colItems, Object
oFolder, Boolean blnAttachments) in D:\NET Projecten\Code Source Sodimex -
Ghost\DocContro l\Business Layer\clsDocCon trol.vb:line 597"
TargetSite: {System.Reflect ion.RuntimeMeth odInfo}

Feb 13 '06 #2
Hi,

I've tryed it, but it didn't work either :-/
And isn't the BackGroundWorke r designed so we shouldn't worry anymore about
those Invoke and Delegates-stuff?

This is my new code with Invoke, which doesn't work either... :-/

Private Sub bgwInfoOutlook_ ProgressChanged (ByVal sender As Object, ByVal
e As System.Componen tModel.Progress ChangedEventArg s) Handles
bgwInfoOutlook. ProgressChanged
Try
SetDataSource()
Catch ex As Exception
ErrorMessage(ex )
End Try
End Sub

Delegate Sub SetDgvCallback( )

Private Sub SetDataSource()
If Me.dgvAdd.Invok eRequired Then
Dim d As New SetDgvCallback( AddressOf SetDataSource)
Me.Invoke(d, Nothing)
Else
Me.dgvAdd.DataS ource = Nothing
Me.dgvAdd.DataS ource = docCtrl.InfoLis t
End If
End Sub

And the werit thing is: the Me.dgvAdd.Invok eRequired returns False...

"Dmytro Lapshyn [MVP]" <x-****@no-spam-please.hotpop.c om> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi Pieter,

As far as I know, .NET 2.0 strictly prohibits any access to the user
interface from background worker threads. This wasn't allowed in .NET 1.1
either, but in that version one sometimes could get away with violating
the rule. Now you'll get the "Cross-thread operation not valid" almost for
sure.

Therefore, to do any updates to the UI properly, you should use the
Control.Invoke method to run the UI update code on the UI thread.

Feb 13 '06 #3
The problem is more serious. You shouldn't be accessing any Outlook objects
from a background thread. It just won't work right and you'll have all sorts
of problems ranging from error messages to mysterious OUTLOOK.EXE processes
that won't shut down.

I'm afraid all of your communication with Outlook has to be done on the same
thread that calls your connect method. That would be the UI thread. The only
"async" methods you can use are the advanced search api's but I believe even
they are single-threaded much like a UI timer is.

--
Josh Einstein
Einstein Technologies
Microsoft Tablet PC MVP
Tablet Enhancements for Outlook 2.0 - Try it free for 14 days
www.tabletoutlook.com
"Pieter" <pi**********@h otmail.com> wrote in message
news:uO******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

I've tryed it, but it didn't work either :-/
And isn't the BackGroundWorke r designed so we shouldn't worry anymore
about those Invoke and Delegates-stuff?

This is my new code with Invoke, which doesn't work either... :-/

Private Sub bgwInfoOutlook_ ProgressChanged (ByVal sender As Object,
ByVal e As System.Componen tModel.Progress ChangedEventArg s) Handles
bgwInfoOutlook. ProgressChanged
Try
SetDataSource()
Catch ex As Exception
ErrorMessage(ex )
End Try
End Sub

Delegate Sub SetDgvCallback( )

Private Sub SetDataSource()
If Me.dgvAdd.Invok eRequired Then
Dim d As New SetDgvCallback( AddressOf SetDataSource)
Me.Invoke(d, Nothing)
Else
Me.dgvAdd.DataS ource = Nothing
Me.dgvAdd.DataS ource = docCtrl.InfoLis t
End If
End Sub

And the werit thing is: the Me.dgvAdd.Invok eRequired returns False...

"Dmytro Lapshyn [MVP]" <x-****@no-spam-please.hotpop.c om> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi Pieter,

As far as I know, .NET 2.0 strictly prohibits any access to the user
interface from background worker threads. This wasn't allowed in .NET 1.1
either, but in that version one sometimes could get away with violating
the rule. Now you'll get the "Cross-thread operation not valid" almost
for sure.

Therefore, to do any updates to the UI properly, you should use the
Control.Invoke method to run the UI update code on the UI thread.


Feb 13 '06 #4
Oh I should also mention that your error here doesn't have anything to do
with the cross-thread Outlook access but I would avoid that anyway.

Your error message here is the same thing Dmytro said about cross-thread UI
calls. Something you are doing in DoWork (which is in a background thread)
is modifying the data grid. You can't do any UI access in DoWork. Only in
ProgressChanged or RunWorkerComple ted.

But again, I would avoid accessing the Outlook API from a background thread.
It is not thread-safe and behaves unpredictably whether or not you employ
locking.

--
Josh Einstein
Einstein Technologies
Microsoft Tablet PC MVP
Tablet Enhancements for Outlook 2.0 - Try it free for 14 days
www.tabletoutlook.com
"Pieter" <pi**********@h otmail.com> wrote in message
news:uO******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

I've tryed it, but it didn't work either :-/
And isn't the BackGroundWorke r designed so we shouldn't worry anymore
about those Invoke and Delegates-stuff?

This is my new code with Invoke, which doesn't work either... :-/

Private Sub bgwInfoOutlook_ ProgressChanged (ByVal sender As Object,
ByVal e As System.Componen tModel.Progress ChangedEventArg s) Handles
bgwInfoOutlook. ProgressChanged
Try
SetDataSource()
Catch ex As Exception
ErrorMessage(ex )
End Try
End Sub

Delegate Sub SetDgvCallback( )

Private Sub SetDataSource()
If Me.dgvAdd.Invok eRequired Then
Dim d As New SetDgvCallback( AddressOf SetDataSource)
Me.Invoke(d, Nothing)
Else
Me.dgvAdd.DataS ource = Nothing
Me.dgvAdd.DataS ource = docCtrl.InfoLis t
End If
End Sub

And the werit thing is: the Me.dgvAdd.Invok eRequired returns False...

"Dmytro Lapshyn [MVP]" <x-****@no-spam-please.hotpop.c om> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi Pieter,

As far as I know, .NET 2.0 strictly prohibits any access to the user
interface from background worker threads. This wasn't allowed in .NET 1.1
either, but in that version one sometimes could get away with violating
the rule. Now you'll get the "Cross-thread operation not valid" almost
for sure.

Therefore, to do any updates to the UI properly, you should use the
Control.Invoke method to run the UI update code on the UI thread.


Feb 13 '06 #5
"Josh Einstein" <jo**********@h otmail.com> wrote in message
news:OW******** ******@TK2MSFTN GP14.phx.gbl...
Your error message here is the same thing Dmytro said about cross-thread
UI calls. Something you are doing in DoWork (which is in a background
thread) is modifying the data grid.


Well actually it isn't :-/
And I don't have the exception while the Dowork is performing its actions:
it happens when the ProgressChanged-event fires...

Feb 13 '06 #6
Why? COM in general (especially out-of-proc COM), and Outlook is particular
can handle cross thread/process calls just fine - all Outlook objects are
apartment threaded, so all calls will end up on the main Outlook thread
anyway.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Josh Einstein" <jo**********@h otmail.com> wrote in message
news:OR******** ******@TK2MSFTN GP09.phx.gbl...
The problem is more serious. You shouldn't be accessing any Outlook
objects from a background thread. It just won't work right and you'll have
all sorts of problems ranging from error messages to mysterious
OUTLOOK.EXE processes that won't shut down.

I'm afraid all of your communication with Outlook has to be done on the
same thread that calls your connect method. That would be the UI thread.
The only "async" methods you can use are the advanced search api's but I
believe even they are single-threaded much like a UI timer is.

--
Josh Einstein
Einstein Technologies
Microsoft Tablet PC MVP
Tablet Enhancements for Outlook 2.0 - Try it free for 14 days
www.tabletoutlook.com
"Pieter" <pi**********@h otmail.com> wrote in message
news:uO******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

I've tryed it, but it didn't work either :-/
And isn't the BackGroundWorke r designed so we shouldn't worry anymore
about those Invoke and Delegates-stuff?

This is my new code with Invoke, which doesn't work either... :-/

Private Sub bgwInfoOutlook_ ProgressChanged (ByVal sender As Object,
ByVal e As System.Componen tModel.Progress ChangedEventArg s) Handles
bgwInfoOutlook. ProgressChanged
Try
SetDataSource()
Catch ex As Exception
ErrorMessage(ex )
End Try
End Sub

Delegate Sub SetDgvCallback( )

Private Sub SetDataSource()
If Me.dgvAdd.Invok eRequired Then
Dim d As New SetDgvCallback( AddressOf SetDataSource)
Me.Invoke(d, Nothing)
Else
Me.dgvAdd.DataS ource = Nothing
Me.dgvAdd.DataS ource = docCtrl.InfoLis t
End If
End Sub

And the werit thing is: the Me.dgvAdd.Invok eRequired returns False...

"Dmytro Lapshyn [MVP]" <x-****@no-spam-please.hotpop.c om> wrote in
message news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi Pieter,

As far as I know, .NET 2.0 strictly prohibits any access to the user
interface from background worker threads. This wasn't allowed in .NET
1.1 either, but in that version one sometimes could get away with
violating the rule. Now you'll get the "Cross-thread operation not
valid" almost for sure.

Therefore, to do any updates to the UI properly, you should use the
Control.Invoke method to run the UI update code on the UI thread.



Feb 13 '06 #7
You'll have to recheck your code. Set a breakpoint and look at the threads
window. You are definitely accessing the UI from the background thread
somewhere. ProgressChanged and RunWorkerComple ted are raised on the UI
thread. (Which is why InvokeRequired returns false.)

--
Josh Einstein
Einstein Technologies
Microsoft Tablet PC MVP
Tablet Enhancements for Outlook 2.0 - Try it free for 14 days
www.tabletoutlook.com
"Pieter" <pi**********@h otmail.com> wrote in message
news:O0******** ******@TK2MSFTN GP10.phx.gbl...
"Josh Einstein" <jo**********@h otmail.com> wrote in message
news:OW******** ******@TK2MSFTN GP14.phx.gbl...
Your error message here is the same thing Dmytro said about cross-thread
UI calls. Something you are doing in DoWork (which is in a background
thread) is modifying the data grid.


Well actually it isn't :-/
And I don't have the exception while the Dowork is performing its actions:
it happens when the ProgressChanged-event fires...

Feb 13 '06 #8
Well as we discussed in another thread, there are pumping and re-entrance
problems with the STA model. But, I don't claim to understand all of these.
What I do know however, is that if I change a line of code in my app that
accesses any of the Outlook API from a background thread, Outlook will fail
to shut down.

I can't speak for out of process, but in process (such as in the case of an
add in) exhibits this behavior for me. It's also one of the main reasons I
gave up on trying to use remoting in another project. And in my research
(sorry I don't have sources at the moment, it was over a year ago) I found
others were recommending to not do this either.

--
Josh Einstein
Einstein Technologies
Microsoft Tablet PC MVP
Tablet Enhancements for Outlook 2.0 - Try it free for 14 days
www.tabletoutlook.com
"Dmitry Streblechenko" <dm****@dimastr .com> wrote in message
news:O8******** ******@TK2MSFTN GP14.phx.gbl...
Why? COM in general (especially out-of-proc COM), and Outlook is
particular can handle cross thread/process calls just fine - all Outlook
objects are apartment threaded, so all calls will end up on the main
Outlook thread anyway.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Josh Einstein" <jo**********@h otmail.com> wrote in message
news:OR******** ******@TK2MSFTN GP09.phx.gbl...
The problem is more serious. You shouldn't be accessing any Outlook
objects from a background thread. It just won't work right and you'll
have all sorts of problems ranging from error messages to mysterious
OUTLOOK.EXE processes that won't shut down.

I'm afraid all of your communication with Outlook has to be done on the
same thread that calls your connect method. That would be the UI thread.
The only "async" methods you can use are the advanced search api's but I
believe even they are single-threaded much like a UI timer is.

--
Josh Einstein
Einstein Technologies
Microsoft Tablet PC MVP
Tablet Enhancements for Outlook 2.0 - Try it free for 14 days
www.tabletoutlook.com
"Pieter" <pi**********@h otmail.com> wrote in message
news:uO******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

I've tryed it, but it didn't work either :-/
And isn't the BackGroundWorke r designed so we shouldn't worry anymore
about those Invoke and Delegates-stuff?

This is my new code with Invoke, which doesn't work either... :-/

Private Sub bgwInfoOutlook_ ProgressChanged (ByVal sender As Object,
ByVal e As System.Componen tModel.Progress ChangedEventArg s) Handles
bgwInfoOutlook. ProgressChanged
Try
SetDataSource()
Catch ex As Exception
ErrorMessage(ex )
End Try
End Sub

Delegate Sub SetDgvCallback( )

Private Sub SetDataSource()
If Me.dgvAdd.Invok eRequired Then
Dim d As New SetDgvCallback( AddressOf SetDataSource)
Me.Invoke(d, Nothing)
Else
Me.dgvAdd.DataS ource = Nothing
Me.dgvAdd.DataS ource = docCtrl.InfoLis t
End If
End Sub

And the werit thing is: the Me.dgvAdd.Invok eRequired returns False...

"Dmytro Lapshyn [MVP]" <x-****@no-spam-please.hotpop.c om> wrote in
message news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi Pieter,

As far as I know, .NET 2.0 strictly prohibits any access to the user
interface from background worker threads. This wasn't allowed in .NET
1.1 either, but in that version one sometimes could get away with
violating the rule. Now you'll get the "Cross-thread operation not
valid" almost for sure.

Therefore, to do any updates to the UI properly, you should use the
Control.Invoke method to run the UI update code on the UI thread.



Feb 13 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2287
by: matt | last post by:
Hi all- I'm trying to port an ajax spell-checker (http://www.broken-notebook.com/spell_checker/index.php) to use with the moin moin wiki and have been somewhat successful. (By successful I mean I can spell check using the php backend and my python port running as cgi-bin). My question is this: moinmoin runs on many python web backends (cgi-bin/mod-python/twisted/standalone). My spell-checker backend runs
8
1413
by: anon | last post by:
Dear Microsoft: In your new ASP.NET 2.0 page model of being able to crosspost to another page, it would seem that if you were to type that word in Google, "crosspost" or "cross post", you will get endless amount of results from the newsgroup police complaining about posters cross posting to many newsgroups as this very message is doing. So to those at Microsoft, and since posting your form results to another page is very very...
0
1907
by: Walter Quirtmair | last post by:
Hello, I have a C# WinForms Application that contains various "old" ActiveX-Controls. Due to some unknown reasons recently the "red cross" - problems appears quite often. Without any know reason suddenly some controls (buttons, toolbars...) will be drawn completely white with a red cross inside it. As I know from other postings this happens if there are exceptions during the painting of the controls. The call stack shown in the...
4
7707
by: J Fisk | last post by:
Hi, I've been banging my head on the wall over this for about two days now so any thoughts are much appreciated. I have a static .svg file with embedded onclick="open()"'s all over. The svg is <embed>ded in a minimal .html file. The onclick's work fine in IE w/Adobe SVG viewer 3: click and a new
4
7788
by: Mau Kae Horng | last post by:
Hello, I have a C# Windows Forms application for machine. Due to some unknown reasons, the application face problems with unexpected exceptions happening, resulting in two red lines forming a red cross across a certain control (the entire form, labels and so on). I get the following message in MessageBox.
5
2050
by: Jared | last post by:
I'd like to display a "please wait while your file is uploading" page immediately after someone uploads a large-ish file. I know I could make something really slick with DHTML, or even something semi-slick using a hidden frame to post the form to. However, both of these approaches carry browser-compatibility risks. It's my understanding that my server-side code doesn't execute until the file is completely received by IIS, so I can't...
11
4287
by: taoberly | last post by:
A few months ago I posted a question about using a file on my hard drive to perform cross-frame scripting and pull data from a server on my company's intranet. I eventually got this working using an HTA file and Internet Explorer. Now I'm tackling a similar issue, but really need to keep the IE menus, navigation buttons, etc. this time around. Assuming a solution exists, I'm guessing it involves using the IE6 SP2 "Mark of the Web"...
93
3981
by: jacob navia | last post by:
In this group there is a bunch of people that call themselves 'regulars' that insist in something called "portability". Portability for them means the least common denominator. Write your code so that it will compile in all old and broken compilers, preferably in such a fashion that it can be moved with no effort from the embedded system in the coffe machine to the 64 bit processor in your desktop.
0
1022
by: newtechiebug | last post by:
I know that Transform and Pivot are not recognized commands in SQL and I have looked everywhere on how to covert the below query to run properly in SQL, but I can't seem to find the answer. If someone could help, that would be awesome. Thanks! TRANSFORM Count(ConfirmOriginRecords.PHNum) AS SELECT ConfirmOriginRecords.SendZip, Count(ConfirmOriginRecords.PHNum) AS FROM ConfirmOriginRecords GROUP BY ConfirmOriginRecords.SendZip PIVOT...
1
1513
by: Luis Freitas | last post by:
I have a table with the following Fields: Article and 8 fields that are Dates. Under each date is a quantity. I would like to run a query that would have only 3 columns: Article, Date and Quantity Thank you very much
0
8774
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.