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

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi,

It's an add-in so I am not sure InvokeRequired works properly. However,
Control.Invoke worked just fine for me in a VS .NET 2003 add-in.

"Pieter" <pietercoucke@xxxxxxxxxxx> wrote in message
news:uOMzr6JMGHA.3104@xxxxxxxxxxxxxxxxxxxxxxx
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-code@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:%23JRvllJMGHA.1536@xxxxxxxxxxxxxxxxxxxxxxx
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.




.



Relevant Pages

  • Re: Need help: Commandbar event
    ... I'm not sure about a VB.net shared add-in, but in other worlds you have to ... Private mbtnMyButton As Office.CommandBarButton ... Private MenuBarItem As CommandBarControl ... Public Sub OnBeginShutdownImplements ...
    (microsoft.public.word.vba.general)
  • Re: Need help: Commandbar event
    ... I'm not sure about a VB.net shared add-in, but in other worlds you have to ... Private mbtnMyButton As Office.CommandBarButton ... Private MenuBarItem As CommandBarControl ... Public Sub OnBeginShutdownImplements ...
    (microsoft.public.word.vba.general)
  • Re: Need help: Commandbar event
    ... I'm not sure about a VB.net shared add-in, but in other worlds you have ... Private mbtnMyButton As Office.CommandBarButton ... Private MenuBarItem As CommandBarControl ... Public Sub OnBeginShutdownImplements ...
    (microsoft.public.word.vba.general)
  • OnDisconnection does not fire
    ... I followed the example from "Outlook Com Add-in ... Public Sub OnBeginShutdownImplements ... Dim oApp As Outlook.Application ...
    (microsoft.public.office.developer.com.add_ins)
  • Re: OnDisconnection does not fire
    ... I followed the example from "Outlook Com Add-in ... > Public Sub OnBeginShutdownImplements ... > Dim oApp As Outlook.Application ...
    (microsoft.public.office.developer.com.add_ins)