03-24-2014 04:27 AM
Hi im using a background worker to create a couple of custom subentiies in an Ac16 Database, the worker just shows a please wait dialog while its processing and closes it when the worker has finished. Its giving a weird threading error while creating one of the entities (others are ok).
Has anybody seen something like this before ?
Controls created on one thread cannot be parented to a control on a different thread. (System.Windows.Forms)
at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at System.Windows.Forms.TabControl.ControlCollection.Add(Control value)
at System.Windows.Forms.TabControl.TabPageCollection.Add(TabPage value)
at Act.UI.ContactViews.ContactDetailView.AddBackofficeTab(ILiveDataTab liveDataTab)
at Act.UI.ContactViews.ContactDetailView.OnLoad(ActApplication actApp)
at Act.Framework.MetaData.SchemaMetaData.Reload(Boolean raiseEvents)
at Act.Framework.Database.DescriptorBaseManager.RefreshSchema(Boolean raiseEvents)
at Act.Framework.Database.DefineEntityManager.CreateSubentity(CreateSubentityInfo& si)
at Act.Framework.Database.DefineEntityManager.CreateSubentity(String entityName, String displayName, Guid entityId, Boolean isDefineField, String description)
at Act.Framework.CustomEntities.CustomEntityManager.CreateCustomSubEntity(String entityName, String displayName, ParentEntity parentEntities, Boolean isDefineField, String description)
at AlphaLogix.Aim50.Plugins.Invoices.InvoiceItemEntityDescriptorFactory.CreateEntity() in e:\p4_pixel1666_HADES\AlphaLogix.Aim50.SDK\AlphaLogix.Aim50.Plugins\Invoices\InvoiceItemEntityDescriptorFactory.cs:line 137
03-24-2014 06:41 AM
A background worker, I believe, creates a completely new thread. Any calls to the UI must be marshalled, so the UI thread ultimately makes the call.
In the code below, I show an example of how this can be done. This code is located on a form (UI), and the routine "Foo" is actually a callback method (I removed a bunch of the specifics for simplicity), which means it's on a different thread than the UI. Since I want to interact with the form (Me), I must initiate the call from an item on the UI thread, with Me being the easiest object.
Private Sub Foo() 'some task Me.Invoke(New delUpdateLog(AddressOf UpdateLog), strMsg) 'finalize/clean-up End Sub Private Delegate Sub delUpdateLog(ByVal str As String) Private Sub UpdateLog(ByVal str As String) rtbLog.AppendText(vbCrLf & str) End Sub
In your case, you'd have to have a control object as your parameter in the Delegate and respective method to be invoked. Then in that method, you'd need to add the passed in control to the proper parent control. I hope this helps.
03-24-2014 07:22 AM
Im not actually doing an UI work in the thread ...the line throwing the error is a call to the act sdk method as follows, ie its the act sdk throwing an error ...not any ui code
CustomEntityDescriptor descriptor = framework.CustomEntities.CreateCustomSubEntity(
InvoiceItemEntityDefinition.ENTITY_NAME, // unique name
InvoiceItemEntityDefinition.ENTITY_DISPLAY_NAME, // display name
// primary entities the custom sub-entity will be associated with
true, // do we want this in define fields (future use)
InvoiceItemEntityDefinition.ENTITY_DESCRPTION); // description of the entity
03-24-2014 07:58 AM
03-24-2014 08:24 AM
Taken away the background worker and it went through ok ......strangely the problem only happened when going live on the customers machine ....didnt happen at all during testing on multiple vms and real machines. Thanks for help
03-24-2014 08:31 AM