The Syncfusion native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
Hi,
I''m getting an exception occasionally in my overridden ComboBoxBarItem. I know why its happening (I''m calling functions in the class from a separate thread than it was created in), however the normal solution - using the ISynchronizeInvoke.InvokeRequired and ISynchronizeInvoke.Invoke doesn''t work because the ComboBoBarItem doesn''t derive from Control (which provides these). Can you please tell me how can I syncronously execute my function in the creating thread, when I''m in another thread?
Thanks,
Sue
This is the exception I get:
An unhandled exception of type ''System.ArgumentException'' occurred in system.windows.forms.dll
Additional information: Controls created on one thread cannot be parented to a control on a different thread.
Unhandled Exception: System.ArgumentException: Controls created on one thread cannot be parented to a control on a different thread.
at System.Windows.Forms.ControlCollection.Add(Control value)
at Syncfusion.Windows.Forms.Tools.XPMenus.EditableComboRenderer.CreateTextBox()
at Syncfusion.Windows.Forms.Tools.XPMenus.EditableComboRenderer..ctor(IBarRenderer parent)
at Syncfusion.Windows.Forms.Tools.XPMenus.BarRenderer.CreateNewRenderer(BarItem barItem)
at Syncfusion.Windows.Forms.Tools.XPMenus.BarRenderer.OnBarItemsCollectionChanged()
at Syncfusion.Windows.Forms.Tools.XPMenus.BarRenderer.Syncfusion.Windows.Forms.Tools.XPMenus.IBarRenderer.UpdateRenderers()
at Syncfusion.Windows.Forms.Tools.XPMenus.ComboBoxItemRenderer.BarItemPropertyChanged(SyncfusionPropertyChangedEventArgs e)
at Syncfusion.Windows.Forms.Tools.XPMenus.BarRenderer.BarItem_PropertyChanged(Object sender, SyncfusionPropertyChangedEventArgs e)
at Syncfusion.ComponentModel.SyncfusionPropertyChangedEventHandler.Invoke(Object sender, SyncfusionPropertyChangedEventArgs e)
at Syncfusion.Windows.Forms.Tools.XPMenus.BarItem.OnPropertyChanged(SyncfusionPropertyChangedEventArgs args)
at Syncfusion.Windows.Forms.Tools.XPMenus.ComboBoxBarItem.set_Editable(Boolean value)
at Runge.Common.UI.FieldRangeComboControl.ItemChanged() in d:\projects\xpac\xpac 8.0\runge.common.ui\fieldrangecombocontrol.cs:line 567
at Runge.Common.UI.FieldRangeComboControl.ItemChanged(Object sender, UpdateEventArgs e) in d:\projects\xpac\xpac 8.0\runge.common.ui\fieldrangecombocontrol.cs:line 555
at Runge.Common.Data.StandardItem.EndUpdate(DateTime startTime, Boolean fireOnParent) in D:\projects\XPAC\XPAC 8.0\Runge.Common.Data\StandardItem.cs:line 216
at Runge.Common.Data.StandardCollection.EndUpdate(DateTime startTime, Boolean fireOnParent) in D:\projects\XPAC\XPAC 8.0\Runge.Common.Data\StandardCollection.cs:line 519
at Runge.Common.Data.StandardItem.EndUpdate(DateTime startTime, Boolean fireOnParent) in D:\projects\XPAC\XPAC 8.0\Runge.Common.Data\StandardItem.cs:line 229
at Runge.Common.Data.StandardCollection.EndUpdate(DateTime startTime, Boolean fireOnParent) in D:\projects\XPAC\XPAC 8.0\Runge.Common.Data\StandardCollection.cs:line 526
at Runge.Common.Data.StandardItem.EndUpdate(DateTime startTime, Boolean fireOnParent) in D:\projects\XPAC\XPAC 8.0\Runge.Common.Data\StandardItem.cs:line 229
at Runge.Common.Data.StandardItem.EndUpdate() in D:\projects\XPAC\XPAC 8.0\Runge.Common.Data\StandardItem.cs:line 197
ADAdministrator Syncfusion Team February 24, 2004 07:46 PM UTC
Hi Sue,
Since the BarItem is not of the type ''Control'', you cannot use the ISynchronizeInvoke.Invoke method to invoke it from another thread. Instead as a workaround, you could have a custom method in the host form which returns the BarItem, and then invoke this custom method by using ISynchronizeInvoke.Invoke on the Form. Please try this and let me know how it goes. Thanks for choosing Syncfusion products.
Regards,
Guru Patwal
Syncfusion, Inc.
SHSue HarrisFebruary 24, 2004 08:14 PM UTC
Guru,
I implemented the class as an override of the combo box bar item, because it is being used in multiple places. So requiring the parent form to have a special function is somewhat impractical. I suppose I could try using the parent controls Invoke and InvokeRequired from the ComboBoxBarItem, but what is the best way (from the ComboBoxBarItem, which is where the event occurs) for me to get the parent control?
Regards,
Sue
ADAdministrator Syncfusion Team February 25, 2004 05:49 PM UTC
Hi Sue,
Please try this approach :
//Get hold of the parent form
Form form = cbarItem.Manager.Form;
//Let the Form implement an interface of the type :
interface IMyCustomInterface
{
void MyCustomMethod();
}
// check if the form implements this interface
if(!(form is IMyCustomInterface))
{
// throw an exception saying the form doesn''t
// implement the necessary interface.
}
// You call this from within CustomComboBoxBarItem:
form.Invoke("MyCustomMethod", new object[]{this}); // ''this'' is the derived ComboBoxBarItem;
//Method in the Form:
private void MyCustomMethod(CustomComboBoxBarItem cbaritem)
{
cbaritem.MyCustomComboBoxBarItemMethod();
}
Please let me know if this meets your requirements. Thanks for choosing Syncfusion products.
Regards,
Guru Patwal
Syncfusion, Inc.