473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 4821
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.