473,473 Members | 1,563 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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}
Feb 13 '06 #1
8 10099
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**********@hotmail.com> wrote in message
news:eU***************@tk2msftngp13.phx.gbl...
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}

Feb 13 '06 #2
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]" <x-****@no-spam-please.hotpop.com> wrote in message
news:%2****************@TK2MSFTNGP11.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**********@hotmail.com> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl...
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]" <x-****@no-spam-please.hotpop.com> wrote in message
news:%2****************@TK2MSFTNGP11.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 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" <pi**********@hotmail.com> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl...
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]" <x-****@no-spam-please.hotpop.com> wrote in message
news:%2****************@TK2MSFTNGP11.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**********@hotmail.com> wrote in message
news:OW**************@TK2MSFTNGP14.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**********@hotmail.com> wrote in message
news:OR**************@TK2MSFTNGP09.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**********@hotmail.com> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl...
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]" <x-****@no-spam-please.hotpop.com> wrote in
message news:%2****************@TK2MSFTNGP11.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 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" <pi**********@hotmail.com> wrote in message
news:O0**************@TK2MSFTNGP10.phx.gbl...
"Josh Einstein" <jo**********@hotmail.com> wrote in message
news:OW**************@TK2MSFTNGP14.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**************@TK2MSFTNGP14.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**********@hotmail.com> wrote in message
news:OR**************@TK2MSFTNGP09.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**********@hotmail.com> wrote in message
news:uO**************@TK2MSFTNGP11.phx.gbl...
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]" <x-****@no-spam-please.hotpop.com> wrote in
message news:%2****************@TK2MSFTNGP11.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
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...
8
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...
0
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...
4
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...
4
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...
5
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...
11
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...
93
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...
0
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...
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
1
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...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.