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}
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}
Comment