Profile Picture

Cross-thread operation not valid

Posted By Martin Oosthuizen 14 Years Ago
Author
Message
Martin Oosthuizen
crazy Posted 14 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 14 Years Ago
Posts: 2, Visits: 1
Hi there.
I was using the Q1 2007 release until now, but am attempting an upgrade to the latest (2010) version. After redoing the references the program compiled without any big problems. But now, when the software runs, and I drag any tab(document) into another docking position it complains:

System.InvalidOperationException was unhandled
Message="Cross-thread operation not valid: Control '' 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.DestroyHandle()
at System.Windows.Forms.Control.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at Nevron.UI.WinForm.Controls.NUIDocument.PerformDispose()
at Nevron.UI.NDisposableObject.Dispose(Boolean disposing)
at Nevron.UI.NDisposableObject.Finalize()
InnerException:

The tabs are created like this (ctlWatchList is a user control with a datagrid):
ctlWatchList m_ctlWatchList = new ctlWatchList(this) { Dock = DockStyle.Fill };
NUIDocument docWatchList = new NUIDocument(WatchListTitle, -1, m_ctlWatchList);
m_DockManager.DocumentManager.AddDocument(docWatchList);


Do you have any ideas about what the problem could be?
What other information will you need from me?

I'd really appreciate the help.

Kind regards,
Martin


JSW W.
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (127 reputation)Supreme Being (127 reputation)Supreme Being (127 reputation)Supreme Being (127 reputation)Supreme Being (127 reputation)Supreme Being (127 reputation)Supreme Being (127 reputation)Supreme Being (127 reputation)Supreme Being (127 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 127, Visits: 1

I have encounter the same problem upgrading from version Q12007 UI to Q1 2010.

My error occurs when using thread.sleep()

 



Angel Chorbadzhiev
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)Supreme Being (142 reputation)

Group: Forum Members
Last Active: Last Month
Posts: 139, Visits: 184

Hi Martin and JSW W.,

I guess you are creating the documents in a separate thread.

If so, please, try to check whether invoke is required when you are creating it, because the UI suite is not thread safe.

You can create the document by the following way:

private void CreateUIDoc()

{

    if (InvokeRequired)

    {

        Invoke(new MethodInvoker(CreateUIDoc));

        return;

    }

    ctlWatchList m_ctlWatchList = new ctlWatchList(this) { Dock = DockStyle.Fill };

    NUIDocument docWatchList = new NUIDocument(WatchListTitle, -1, m_ctlWatchList);

    m_DockManager.DocumentManager.AddDocument(docWatchList);

}

Other option that you can try is to switch off the cross thread check by setting Control.CheckForIllegalCrossThreadCalls to false.

However, the first approach is recommended.

Please, let us know if you still have this problem.

Regards,

Angel Chorbadzhiev.



Martin Oosthuizen
Posted 14 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 14 Years Ago
Posts: 2, Visits: 1
Hi Angel, thanks very much for the response.
The CheckForIllegalCrossThreadCalls setting does fix the problem, although I agree, the better solution would be to make the call thread-safe.
But just to let everyone know, that did the trick for me.

JSW W.
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (127 reputation)Supreme Being (127 reputation)Supreme Being (127 reputation)Supreme Being (127 reputation)Supreme Being (127 reputation)Supreme Being (127 reputation)Supreme Being (127 reputation)Supreme Being (127 reputation)Supreme Being (127 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 127, Visits: 1

Thanks Angel for your help. We have a large project so it hard to find the problem, you have managed to resolve it!!! I almost gave up there.

Well, I am new to Nevron and I am customers to ComponentOne, Dundas, Telerik, and now Nevron.

My honest opinion was that Telerik service was good but Nevron personal service is off the chart!!!

Recommend to anyone

 



Nevron Support
Posted 14 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi JSW,

 

We appreciate your king word and recommendations

You should also go with Nevron Chart for .NET – the charting control features unmatched set of features and has numerous advantages compared to solutions from other vendors. For more details contact Nevron Sales

 

Kind regards,

Nevron Support Team

Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic