|
Rank: Guest
Groups:
Joined: 2/14/2015 Posts: 1,322
|
I want to run the GUIExample VB.Net on VS2005 Here is whaT I get when calling the spellcheck dialog:
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.set_WindowText(String value) at System.Windows.Forms.Control.set_Text(String value) at System.Windows.Forms.Label.set_Text(String value) at cb.b() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
What can I do against this? Jakob
JRS
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
Hi Jakob, please update to v3.6 which is compatible with VS 2005 You shouldn't have any trouble, but please see the release notes for information regarding the licenses.licx file. Let us know if you have any questions please, Jim -your feedback is helpful to other users, thank you!
|
|
Rank: Member
Groups: Registered
Joined: 5/5/2010 Posts: 14
|
Hi,
I am getting same error message. I am using latest version of components (4.6.1.204)
StackTrace -
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 Keyoti.RapidSpell.TextBoxBaseIAYTAdapter.a..ctor(TextBoxBase A_0, TextBoxBaseIAYTAdapter A_1) at Keyoti.RapidSpell.TextBoxBaseIAYTAdapter.AddHandlers() at Keyoti.RapidSpell.TextBoxBaseIAYTAdapter..ctor(TextBoxBase tbb, Boolean createCutCopyPasteReplacement) at Keyoti.RapidSpell.TextBoxBaseIAYTAdapter.a(TextBoxBase A_0, Boolean A_1) at Keyoti.RapidSpell.RapidSpellAsYouType.RemoveTextBoxBase(TextBoxBase textComponent)
Please suggest.
Thanks in advance.
Pravin
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
Hi Pravin, are you calling RemoveTextBoxBase from a thread that you've created? If so, you need to Invoke that method instead; http://msdn.microsoft.com/en-us/library/ms171728(VS.80).aspx Jim -your feedback is helpful to other users, thank you!-your feedback is helpful to other users, thank you!
|
|
Rank: Member
Groups: Registered
Joined: 5/5/2010 Posts: 14
|
Thanks for response, Jim.
Yes, TextControl.InvokeRequired is true in this case. I am not sure how to call Invoke in our case. I will give more details.
I have a static public class SpellCheckEngine which has methods like AddTextControl, RemoveTextControl which internally calls RapidSpellAsYouTypeObject.AddTextBoxBase(txtControl) and RapidSpellAsYouTypeObject.RemoveTextBoxBase(txtControl). These methods gets called by our custom TextBox on Load and on Dispose. This static class has private static instances of RapidSpellAsYouType, RapidSpellAYTDialogCoupler and RapidSpellDialog objects.
We face this error only if TextControl is a First Control in the Form (as on date).
Also after this exception, it starts throwing same exceptions for AddTextBoxBase() method and we have to restart client.
As I have a static class, how can I call Invoke Method? Any suggestions are appreciated.
public static void AddTextControl(TextBoxBase txtControl) { lock (syncRoot) { RapidSpellAsYouTypeObject.AddTextBoxBase(txtControl); } }
public static void RemoveTextControl(TextBoxBase txtControl) { lock (syncRoot) { RapidSpellAsYouTypeObject.RemoveTextBoxBase(txtControl); } }
|
|
Rank: Member
Groups: Registered
Joined: 5/5/2010 Posts: 14
|
Forgot to mention... We face this error only if 1. if TextControl is a First Control in the Form (as on date) and 2. If Form is opened and closed without doing anything i.e. did not type anything in textbox / keep the text control blank
If type something in the control and close the form, no error occurs.
It looks weird to me.
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
Yes that is very odd, Pravin. You're using a plain TextBox, or RichTextBox? How/where do you call RemoveTextControl? In the form Dispose? You shouldn't need to by the way, we do that for you in dispose. The nature of the error makes me think that it's not something that you can control though - if we can't get anywhere from the questions above, I'll have to ask for a project that demonstrates it.... Best Jim -your feedback is helpful to other users, thank you!-your feedback is helpful to other users, thank you!
|
|
Rank: Member
Groups: Registered
Joined: 5/5/2010 Posts: 14
|
I am using a class derived from TextBox. On load of this control, we use AddTextControl(this) of static class SpellCheckEngine. We were calling the RemoveTextControl method in Dispose method.
When this code has been removed, it throws the same exception for its parent container class at base.Dispose().
If we do not add RapidSpell object (i.e. do not call "AddTextControl") in control, it does not throw any exception.
Is it due to static methods in Static class SpellCheckEngine?
The structure of SpellCheckEngine is as follows
3 static instances of RapidSpellAsYouType, RapidSpellAYTDialogCoupler and RapidSpellDialog.
3 static methods AddTextControl(), RemoveTextControl () and ShowSpellDialog() which internally uses above 3 object instances.
Thanks,
Pravin
|
|
Rank: Member
Groups: Registered
Joined: 5/5/2010 Posts: 14
|
This issue is resolved.
The problem was handle of parent control was missing while dispoing the control. (strange!!!) The following code has done the trick. Rough Code for your reference.
{ . . delegateInvokeDispose disposeDelegate = new delegateInvokeDispose(disposeByInvoke);
IntPtr i = IntPtr.Zero;
//This make sure that Control's handle exists. if it is not there, it will be created internally. if (!control.IsHandleCreated) i = control.Handle; control.Invoke(disposeDelegate, new object[] { control }); . . . }
private void disposeByInvoke(Control controlToDispose) { controlToDispose.Dispose(); }
Thanks for your help, Jim.
Cheers,
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
Thanks Pravin, it's interesting that this would manifest itself in the error that it did.... Jim -your feedback is helpful to other users, thank you!-your feedback is helpful to other users, thank you!
|
|
Rank: Member
Groups: Registered
Joined: 1/3/2014 Posts: 1
|
Hi there
We have picked this code up from Pravin and am now developing this in VS2010 (Windows 7.). While in debug mode we are still getting this issue. Can you help please.
Thank you in advance
Paul Marks
|
|
Rank: Advanced Member
Groups: Administrators, Registered
Joined: 8/13/2004 Posts: 2,669 Location: Canada
|
Hi Paul, I've reread the thread - at this point I think the only way to help would be to get a runnable project from you that reproduces it please. From above it looked like the problem was you were calling Dispose on the textbox from a non UI thread (without using Invoke) - is it possible that your code is doing that again? Best Jim -your feedback is helpful to other users, thank you!-your feedback is helpful to other users, thank you!
|
|