A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

BackGroundWorker.ProgressChanged "Cross-thread operation not valid" at 2nd/3th/... progress



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 13th 06, 11:21 AM posted to microsoft.public.dotnet.framework,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb,microsoft.public.outlook.program_vba
Pieter
external usenet poster
 
Posts: 27
Default BackGroundWorker.ProgressChanged "Cross-thread operation not valid" at 2nd/3th/... progress

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.PerformLayoutPri vate(Boolean
useRowShortcut, Boolean computeVisibleRows, Boolean
invalidInAdjustFillingColumns, Boolean repositionEditingControl)
at
System.Windows.Forms.DataGridView.OnColumnWidthCha nged(DataGridViewColumnEventArgs
e)
at
System.Windows.Forms.DataGridView.OnBandThicknessC hanged(DataGridViewBand
dataGridViewBand)
at System.Windows.Forms.DataGridViewBand.set_Thicknes sInternal(Int32
value)
at System.Windows.Forms.DataGridView.AdjustFillingCol umns()
at System.Windows.Forms.DataGridView.ComputeLayout()
at System.Windows.Forms.DataGridView.PerformLayoutPri vate(Boolean
useRowShortcut, Boolean computeVisibleRows, Boolean
invalidInAdjustFillingColumns, Boolean repositionEditingControl)
at System.Windows.Forms.DataGridView.ResetUIState(Boo lean useRowShortcut,
Boolean computeVisibleRows)
at
System.Windows.Forms.DataGridViewRowCollection.OnC ollectionChanged_PreNotification(CollectionChangeA ction
cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow& dataGridViewRow,
Boolean changeIsInsertion)
at
System.Windows.Forms.DataGridViewRowCollection.OnC ollectionChanged(CollectionChangeEventArgs
e, Int32 rowIndex, Int32 rowCount, Boolean changeIsDeletion, Boolean
changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell)
at System.Windows.Forms.DataGridViewRowCollection.Ins ertInternal(Int32
rowIndex, DataGridViewRow dataGridViewRow, Boolean force)
at
System.Windows.Forms.DataGridView.DataGridViewData Connection.ProcessListChanged(ListChangedEventArgs
e)
at
System.Windows.Forms.DataGridView.DataGridViewData Connection.currencyManager_ListChanged(Object
sender, ListChangedEventArgs e)
at
System.Windows.Forms.CurrencyManager.OnListChanged (ListChangedEventArgs e)
at System.Windows.Forms.CurrencyManager.List_ListChan ged(Object sender,
ListChangedEventArgs e)
at System.ComponentModel.BindingList`1.OnListChanged( ListChangedEventArgs
e)
at System.ComponentModel.BindingList`1.FireListChange d(ListChangedType
type, Int32 index)
at System.ComponentModel.BindingList`1.InsertItem(Int 32 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}


Ads
  #2  
Old February 13th 06, 12:31 PM posted to microsoft.public.dotnet.framework,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb,microsoft.public.outlook.program_vba
Dmytro Lapshyn [MVP]
external usenet poster
 
Posts: 1
Default BackGroundWorker.ProgressChanged "Cross-thread operation not valid" at 2nd/3th/... progress

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" wrote in message
...
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.PerformLayoutPri vate(Boolean
useRowShortcut, Boolean computeVisibleRows, Boolean
invalidInAdjustFillingColumns, Boolean repositionEditingControl)
at
System.Windows.Forms.DataGridView.OnColumnWidthCha nged(DataGridViewColumnEventArgs
e)
at
System.Windows.Forms.DataGridView.OnBandThicknessC hanged(DataGridViewBand
dataGridViewBand)
at System.Windows.Forms.DataGridViewBand.set_Thicknes sInternal(Int32
value)
at System.Windows.Forms.DataGridView.AdjustFillingCol umns()
at System.Windows.Forms.DataGridView.ComputeLayout()
at System.Windows.Forms.DataGridView.PerformLayoutPri vate(Boolean
useRowShortcut, Boolean computeVisibleRows, Boolean
invalidInAdjustFillingColumns, Boolean repositionEditingControl)
at System.Windows.Forms.DataGridView.ResetUIState(Boo lean
useRowShortcut, Boolean computeVisibleRows)
at
System.Windows.Forms.DataGridViewRowCollection.OnC ollectionChanged_PreNotification(CollectionChangeA ction
cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow& dataGridViewRow,
Boolean changeIsInsertion)
at
System.Windows.Forms.DataGridViewRowCollection.OnC ollectionChanged(CollectionChangeEventArgs
e, Int32 rowIndex, Int32 rowCount, Boolean changeIsDeletion, Boolean
changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell)
at System.Windows.Forms.DataGridViewRowCollection.Ins ertInternal(Int32
rowIndex, DataGridViewRow dataGridViewRow, Boolean force)
at
System.Windows.Forms.DataGridView.DataGridViewData Connection.ProcessListChanged(ListChangedEventArgs
e)
at
System.Windows.Forms.DataGridView.DataGridViewData Connection.currencyManager_ListChanged(Object
sender, ListChangedEventArgs e)
at
System.Windows.Forms.CurrencyManager.OnListChanged (ListChangedEventArgs e)
at System.Windows.Forms.CurrencyManager.List_ListChan ged(Object sender,
ListChangedEventArgs e)
at
System.ComponentModel.BindingList`1.OnListChanged( ListChangedEventArgs e)
at System.ComponentModel.BindingList`1.FireListChange d(ListChangedType
type, Int32 index)
at System.ComponentModel.BindingList`1.InsertItem(Int 32 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}




  #3  
Old February 13th 06, 01:09 PM posted to microsoft.public.dotnet.framework,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb,microsoft.public.outlook.program_vba
Pieter
external usenet poster
 
Posts: 27
Default BackGroundWorker.ProgressChanged "Cross-thread operation not valid" at 2nd/3th/... progress

Hi,

I've tryed it, but it didn't work either :-/
And isn't the BackGroundWorker 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.ComponentModel.ProgressChangedEventArgs) Handles
bgwInfoOutlook.ProgressChanged
Try
SetDataSource()
Catch ex As Exception
ErrorMessage(ex)
End Try
End Sub

Delegate Sub SetDgvCallback()

Private Sub SetDataSource()
If Me.dgvAdd.InvokeRequired Then
Dim d As New SetDgvCallback(AddressOf SetDataSource)
Me.Invoke(d, Nothing)
Else
Me.dgvAdd.DataSource = Nothing
Me.dgvAdd.DataSource = docCtrl.InfoList
End If
End Sub

And the werit thing is: the Me.dgvAdd.InvokeRequired returns False...

"Dmytro Lapshyn [MVP]" wrote in message
...
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.



  #4  
Old February 13th 06, 03:54 PM posted to microsoft.public.dotnet.framework,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb,microsoft.public.outlook.program_vba
Josh Einstein
external usenet poster
 
Posts: 57
Default BackGroundWorker.ProgressChanged "Cross-thread operation not valid" at 2nd/3th/... progress

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" wrote in message
...
Hi,

I've tryed it, but it didn't work either :-/
And isn't the BackGroundWorker 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.ComponentModel.ProgressChangedEventArgs) Handles
bgwInfoOutlook.ProgressChanged
Try
SetDataSource()
Catch ex As Exception
ErrorMessage(ex)
End Try
End Sub

Delegate Sub SetDgvCallback()

Private Sub SetDataSource()
If Me.dgvAdd.InvokeRequired Then
Dim d As New SetDgvCallback(AddressOf SetDataSource)
Me.Invoke(d, Nothing)
Else
Me.dgvAdd.DataSource = Nothing
Me.dgvAdd.DataSource = docCtrl.InfoList
End If
End Sub

And the werit thing is: the Me.dgvAdd.InvokeRequired returns False...

"Dmytro Lapshyn [MVP]" wrote in message
...
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.





  #5  
Old February 13th 06, 04:00 PM posted to microsoft.public.dotnet.framework,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb,microsoft.public.outlook.program_vba
Josh Einstein
external usenet poster
 
Posts: 57
Default BackGroundWorker.ProgressChanged "Cross-thread operation not valid" at 2nd/3th/... progress

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 RunWorkerCompleted.

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" wrote in message
...
Hi,

I've tryed it, but it didn't work either :-/
And isn't the BackGroundWorker 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.ComponentModel.ProgressChangedEventArgs) Handles
bgwInfoOutlook.ProgressChanged
Try
SetDataSource()
Catch ex As Exception
ErrorMessage(ex)
End Try
End Sub

Delegate Sub SetDgvCallback()

Private Sub SetDataSource()
If Me.dgvAdd.InvokeRequired Then
Dim d As New SetDgvCallback(AddressOf SetDataSource)
Me.Invoke(d, Nothing)
Else
Me.dgvAdd.DataSource = Nothing
Me.dgvAdd.DataSource = docCtrl.InfoList
End If
End Sub

And the werit thing is: the Me.dgvAdd.InvokeRequired returns False...

"Dmytro Lapshyn [MVP]" wrote in message
...
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.





  #6  
Old February 13th 06, 04:10 PM posted to microsoft.public.dotnet.framework,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb,microsoft.public.outlook.program_vba
Pieter
external usenet poster
 
Posts: 27
Default BackGroundWorker.ProgressChanged "Cross-thread operation not valid" at 2nd/3th/... progress

"Josh Einstein" wrote in message
...

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...



  #7  
Old February 13th 06, 04:47 PM posted to microsoft.public.dotnet.framework,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb,microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default BackGroundWorker.ProgressChanged "Cross-thread operation not valid" at 2nd/3th/... progress

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" wrote in message
...
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" wrote in message
...
Hi,

I've tryed it, but it didn't work either :-/
And isn't the BackGroundWorker 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.ComponentModel.ProgressChangedEventArgs) Handles
bgwInfoOutlook.ProgressChanged
Try
SetDataSource()
Catch ex As Exception
ErrorMessage(ex)
End Try
End Sub

Delegate Sub SetDgvCallback()

Private Sub SetDataSource()
If Me.dgvAdd.InvokeRequired Then
Dim d As New SetDgvCallback(AddressOf SetDataSource)
Me.Invoke(d, Nothing)
Else
Me.dgvAdd.DataSource = Nothing
Me.dgvAdd.DataSource = docCtrl.InfoList
End If
End Sub

And the werit thing is: the Me.dgvAdd.InvokeRequired returns False...

"Dmytro Lapshyn [MVP]" wrote in
message ...
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.







  #8  
Old February 13th 06, 05:29 PM posted to microsoft.public.dotnet.framework,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb,microsoft.public.outlook.program_vba
Josh Einstein
external usenet poster
 
Posts: 57
Default BackGroundWorker.ProgressChanged "Cross-thread operation not valid" at 2nd/3th/... progress

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 RunWorkerCompleted 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" wrote in message
...
"Josh Einstein" wrote in message
...

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...





  #9  
Old February 13th 06, 05:39 PM posted to microsoft.public.dotnet.framework,microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb,microsoft.public.outlook.program_vba
Josh Einstein
external usenet poster
 
Posts: 57
Default BackGroundWorker.ProgressChanged "Cross-thread operation not valid" at 2nd/3th/... progress

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" wrote in message
...
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" wrote in message
...
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" wrote in message
...
Hi,

I've tryed it, but it didn't work either :-/
And isn't the BackGroundWorker 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.ComponentModel.ProgressChangedEventArgs) Handles
bgwInfoOutlook.ProgressChanged
Try
SetDataSource()
Catch ex As Exception
ErrorMessage(ex)
End Try
End Sub

Delegate Sub SetDgvCallback()

Private Sub SetDataSource()
If Me.dgvAdd.InvokeRequired Then
Dim d As New SetDgvCallback(AddressOf SetDataSource)
Me.Invoke(d, Nothing)
Else
Me.dgvAdd.DataSource = Nothing
Me.dgvAdd.DataSource = docCtrl.InfoList
End If
End Sub

And the werit thing is: the Me.dgvAdd.InvokeRequired returns False...

"Dmytro Lapshyn [MVP]" wrote in
message ...
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.








 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2002 "The operation Failed" when clicking Send/Receive Douglas Hay Outlook - General Queries 2 March 6th 06 04:34 PM
How Do I Set Free/Busy to show "no information" cross hatches? zrated2 Outlook - Calandaring 1 February 10th 06 09:02 PM
Outlook.ApplicationClass.CreateItem: "The operation failed." Bruce Wood Outlook and VBA 2 February 1st 06 01:12 AM
can't send/receive in OL2003. "operation failed. object missing" sk Outlook - Installation 0 January 26th 06 01:40 PM
Why is "FAX" a valid e-mail type in address book? Opus Outlook - Using Contacts 3 January 13th 06 08:24 PM


All times are GMT +1. The time now is 12:25 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2024 Outlook Banter.
The comments are property of their posters.