Advertisement

03.26.2008 at 03:59AM PDT, ID: 23269913
[x]
Attachment Details

Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on.

Asked by rwallacej in Microsoft Visual Basic.Net, .NET, .NET Framework 2.x

Tags: ,

hi experts,
I see quite a lot of questions on this error but haven't figured it out.
Here's the situation
MAIN FORM-->User clicks on menu and is presented with new form "CalculationsForm"

Dim f As New CalculationsForm()
f.ShowDialog()

User picks some stuff and clicks "OK" on "CalculationsForm. "OK" starts the calculations

 Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Try
            Me.OK_Button.Enabled = False

            ProgressLabel.Show()
            ProgressBar1.Show()

            ProgressStatus = 0

'start calculations here
            BackgroundWorker1.RunWorkerAsync()
        Catch ex As Exception
            Utils.LogException(ex)
        End Try
    End Sub

  Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
do lots of stuff here.....

'finished doing stuff
  BackgroundWorker1.ReportProgress(100)

'Now close the form: ERROR HERE!
Me.close

  end sub

The line "Me.close" gives error. I have tried putting it in the Backgroundworker completed too but no joy.

I just want to close the form on completion of calcs without this cross-thread error.

Help please thank-youStart Free Trial
 
 
[+][-]03.26.2008 at 05:12AM PDT, ID: 21210728

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.26.2008 at 07:35AM PDT, ID: 21212033

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.26.2008 at 09:57PM PDT, ID: 21218693

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, .NET, .NET Framework 2.x
Tags: microsoft, vb.net
Sign Up Now!
Solution Provided By: Idle_Mind
Participating Experts: 3
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628