P
Pieter
Hi,
I'm having some weird problem using the BackGroundWorker in an Outlook
(2003) Add-In, with VB.NET 2005:
I'm using the BackGroundWorker 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.bgwInfoOutlook.RunWorkerAsync(Me.m_colItems)
Private Sub bgwInfoOutlook_DoWork(ByVal sender As Object, ByVal e As
System.ComponentModel.DoWorkEventArgs) Handles bgwInfoOutlook.DoWork
Dim col As Collection = e.Argument
AddHandler docCtrl.InfoListChanged, AddressOf InfoListChanged
Dim str As String = docCtrl.GetOutlookInfo(col,
Me.m_objOutlookFolder)
e.Result = docCtrl.AddedDocMails
End Sub
Private Sub InfoListChanged(ByVal sender As Object, ByVal e As
EventArgs)
Me.bgwInfoOutlook.ReportProgress(0)
End Sub
Private Sub bgwInfoOutlook_ProgressChanged(ByVal sender As Object, ByVal
e As System.ComponentModel.ProgressChangedEventArgs) Handles
bgwInfoOutlook.ProgressChanged
'bind the list to the datagridview
Try
Me.dgvAdd.DataSource = Nothing
Me.dgvAdd.DataSource = docCtrl.InfoList
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.InvalidOperationException: {"Cross-thread operation not valid:
Control 'dgvAdd' accessed from a thread other than the thread it was created
on."}
Data: {System.Collections.ListDictionaryInternal}
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.get_Handle()
at System.Windows.Forms.Control.get_InternalHandle()
at System.Windows.Forms.Control.get_CreateParams()
at System.Windows.Forms.ScrollBar.get_CreateParams()
at System.Windows.Forms.VScrollBar.get_CreateParams()
at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32
width, Int32 height)
at System.Windows.Forms.Control.SetBoundsCore(Int32 x, Int32 y, Int32
width, Int32 height, BoundsSpecified specified)
at System.Windows.Forms.Control.SetBounds(Int32 x, Int32 y, Int32 width,
Int32 height, BoundsSpecified specified)
at System.Windows.Forms.Control.set_Bounds(Rectangle value)
at System.Windows.Forms.DataGridView.LayoutScrollBars()
at System.Windows.Forms.DataGridView.ComputeLayout()
at System.Windows.Forms.DataGridView.PerformLayoutPrivate(Boolean
useRowShortcut, Boolean computeVisibleRows, Boolean
invalidInAdjustFillingColumns, Boolean repositionEditingControl)
at
System.Windows.Forms.DataGridView.OnColumnWidthChanged(DataGridViewColumnEventArgs
e)
at
System.Windows.Forms.DataGridView.OnBandThicknessChanged(DataGridViewBand
dataGridViewBand)
at System.Windows.Forms.DataGridViewBand.set_ThicknessInternal(Int32
value)
at System.Windows.Forms.DataGridView.AdjustFillingColumns()
at System.Windows.Forms.DataGridView.ComputeLayout()
at System.Windows.Forms.DataGridView.PerformLayoutPrivate(Boolean
useRowShortcut, Boolean computeVisibleRows, Boolean
invalidInAdjustFillingColumns, Boolean repositionEditingControl)
at System.Windows.Forms.DataGridView.ResetUIState(Boolean useRowShortcut,
Boolean computeVisibleRows)
at
System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PreNotification(CollectionChangeAction
cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow& dataGridViewRow,
Boolean changeIsInsertion)
at
System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged(CollectionChangeEventArgs
e, Int32 rowIndex, Int32 rowCount, Boolean changeIsDeletion, Boolean
changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell)
at System.Windows.Forms.DataGridViewRowCollection.InsertInternal(Int32
rowIndex, DataGridViewRow dataGridViewRow, Boolean force)
at
System.Windows.Forms.DataGridView.DataGridViewDataConnection.ProcessListChanged(ListChangedEventArgs
e)
at
System.Windows.Forms.DataGridView.DataGridViewDataConnection.currencyManager_ListChanged(Object
sender, ListChangedEventArgs e)
at
System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e)
at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender,
ListChangedEventArgs e)
at System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs
e)
at System.ComponentModel.BindingList`1.FireListChanged(ListChangedType
type, Int32 index)
at System.ComponentModel.BindingList`1.InsertItem(Int32 index, T item)
at System.Collections.ObjectModel.Collection`1.Add(T item)
at BaseFramework.clsBaseList`1.Add(T item) in D:\NET Projecten\Code
Source Sodimex - Ghost\BaseFramework\clsBaseList.vb:line 461
at DocControl.clsDocControl.GetOutlookInfo(Collection colItems, Object
oFolder, Boolean blnAttachments) in D:\NET Projecten\Code Source Sodimex -
Ghost\DocControl\Business Layer\clsDocControl.vb:line 597"
TargetSite: {System.Reflection.RuntimeMethodInfo}
I'm having some weird problem using the BackGroundWorker in an Outlook
(2003) Add-In, with VB.NET 2005:
I'm using the BackGroundWorker 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.bgwInfoOutlook.RunWorkerAsync(Me.m_colItems)
Private Sub bgwInfoOutlook_DoWork(ByVal sender As Object, ByVal e As
System.ComponentModel.DoWorkEventArgs) Handles bgwInfoOutlook.DoWork
Dim col As Collection = e.Argument
AddHandler docCtrl.InfoListChanged, AddressOf InfoListChanged
Dim str As String = docCtrl.GetOutlookInfo(col,
Me.m_objOutlookFolder)
e.Result = docCtrl.AddedDocMails
End Sub
Private Sub InfoListChanged(ByVal sender As Object, ByVal e As
EventArgs)
Me.bgwInfoOutlook.ReportProgress(0)
End Sub
Private Sub bgwInfoOutlook_ProgressChanged(ByVal sender As Object, ByVal
e As System.ComponentModel.ProgressChangedEventArgs) Handles
bgwInfoOutlook.ProgressChanged
'bind the list to the datagridview
Try
Me.dgvAdd.DataSource = Nothing
Me.dgvAdd.DataSource = docCtrl.InfoList
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.InvalidOperationException: {"Cross-thread operation not valid:
Control 'dgvAdd' accessed from a thread other than the thread it was created
on."}
Data: {System.Collections.ListDictionaryInternal}
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.get_Handle()
at System.Windows.Forms.Control.get_InternalHandle()
at System.Windows.Forms.Control.get_CreateParams()
at System.Windows.Forms.ScrollBar.get_CreateParams()
at System.Windows.Forms.VScrollBar.get_CreateParams()
at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32
width, Int32 height)
at System.Windows.Forms.Control.SetBoundsCore(Int32 x, Int32 y, Int32
width, Int32 height, BoundsSpecified specified)
at System.Windows.Forms.Control.SetBounds(Int32 x, Int32 y, Int32 width,
Int32 height, BoundsSpecified specified)
at System.Windows.Forms.Control.set_Bounds(Rectangle value)
at System.Windows.Forms.DataGridView.LayoutScrollBars()
at System.Windows.Forms.DataGridView.ComputeLayout()
at System.Windows.Forms.DataGridView.PerformLayoutPrivate(Boolean
useRowShortcut, Boolean computeVisibleRows, Boolean
invalidInAdjustFillingColumns, Boolean repositionEditingControl)
at
System.Windows.Forms.DataGridView.OnColumnWidthChanged(DataGridViewColumnEventArgs
e)
at
System.Windows.Forms.DataGridView.OnBandThicknessChanged(DataGridViewBand
dataGridViewBand)
at System.Windows.Forms.DataGridViewBand.set_ThicknessInternal(Int32
value)
at System.Windows.Forms.DataGridView.AdjustFillingColumns()
at System.Windows.Forms.DataGridView.ComputeLayout()
at System.Windows.Forms.DataGridView.PerformLayoutPrivate(Boolean
useRowShortcut, Boolean computeVisibleRows, Boolean
invalidInAdjustFillingColumns, Boolean repositionEditingControl)
at System.Windows.Forms.DataGridView.ResetUIState(Boolean useRowShortcut,
Boolean computeVisibleRows)
at
System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PreNotification(CollectionChangeAction
cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow& dataGridViewRow,
Boolean changeIsInsertion)
at
System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged(CollectionChangeEventArgs
e, Int32 rowIndex, Int32 rowCount, Boolean changeIsDeletion, Boolean
changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell)
at System.Windows.Forms.DataGridViewRowCollection.InsertInternal(Int32
rowIndex, DataGridViewRow dataGridViewRow, Boolean force)
at
System.Windows.Forms.DataGridView.DataGridViewDataConnection.ProcessListChanged(ListChangedEventArgs
e)
at
System.Windows.Forms.DataGridView.DataGridViewDataConnection.currencyManager_ListChanged(Object
sender, ListChangedEventArgs e)
at
System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e)
at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender,
ListChangedEventArgs e)
at System.ComponentModel.BindingList`1.OnListChanged(ListChangedEventArgs
e)
at System.ComponentModel.BindingList`1.FireListChanged(ListChangedType
type, Int32 index)
at System.ComponentModel.BindingList`1.InsertItem(Int32 index, T item)
at System.Collections.ObjectModel.Collection`1.Add(T item)
at BaseFramework.clsBaseList`1.Add(T item) in D:\NET Projecten\Code
Source Sodimex - Ghost\BaseFramework\clsBaseList.vb:line 461
at DocControl.clsDocControl.GetOutlookInfo(Collection colItems, Object
oFolder, Boolean blnAttachments) in D:\NET Projecten\Code Source Sodimex -
Ghost\DocControl\Business Layer\clsDocControl.vb:line 597"
TargetSite: {System.Reflection.RuntimeMethodInfo}