Click here to Skip to main content
15,890,670 members
Home / Discussions / C#
   

C#

 
QuestionIllegal cross thread exception in Invoke method Pin
yeah100017-Mar-10 4:21
yeah100017-Mar-10 4:21 
AnswerRe: Illegal cross thread exception in Invoke method Pin
Abhinav S17-Mar-10 4:51
Abhinav S17-Mar-10 4:51 
GeneralRe: Illegal cross thread exception in Invoke method Pin
AspDotNetDev17-Mar-10 12:30
protectorAspDotNetDev17-Mar-10 12:30 
GeneralRe: Illegal cross thread exception in Invoke method Pin
Luc Pattyn17-Mar-10 12:52
sitebuilderLuc Pattyn17-Mar-10 12:52 
AnswerRe: Illegal cross thread exception in Invoke method Pin
Dave Kreskowiak17-Mar-10 4:59
mveDave Kreskowiak17-Mar-10 4:59 
GeneralRe: Illegal cross thread exception in Invoke method [modified] Pin
yeah100017-Mar-10 5:07
yeah100017-Mar-10 5:07 
GeneralRe: Illegal cross thread exception in Invoke method Pin
Luc Pattyn17-Mar-10 5:14
sitebuilderLuc Pattyn17-Mar-10 5:14 
GeneralRe: Illegal cross thread exception in Invoke method Pin
AspDotNetDev17-Mar-10 12:24
protectorAspDotNetDev17-Mar-10 12:24 
FYI, this is what code looks like when you wrap it in PRE tags and specify C# for the LANG attribute, as Luc mentioned:
C#
// Delegate:
private delegate void ChangeTextDelegate(string text);

// Method:
public static void ChangeText(string text)
{
    if (richtextbox1.InvokeRequired)
    {
        richtextbox1.Invoke(new ChangeTextDelegate(ChangeText), new object[] { text });
    }
    else
    {
        int startIndex;
        startIndex = richtextbox1.TextLength; // <- Exception points here.
        // ...
    }
}

Not sure why you are getting an exception there (perhaps post a screenshot and the full text of the exception?), but you might try the following to see if it works (changes in bold):
C#
// Delegate:
private delegate void ChangeTextDelegate(string text);

// Method:
public static void ChangeText(string text)
{
    if (<big><big>this</big></big>.InvokeRequired)
    {
        <big><big>this</big></big>.Invoke(new ChangeTextDelegate(ChangeText), new object[] { text });
    }
    else
    {
        int startIndex;
        startIndex = richtextbox1.TextLength; // <- Exception points here.
        // ...
    }
}

FYI, here is what I typed to make the code look like it does above:
HTML
<pre lang="C#">// Delegate:
private delegate void ChangeTextDelegate(string text);

// Method:
public static void ChangeText(string text)
{
    if (<b><big><big><u>this</u></big></big></b>.InvokeRequired)
    {
        <b><big><big><u>this</u></big></big></b>.Invoke(new ChangeTextDelegate(ChangeText), new object[] { text });
    }
    else
    {
        int startIndex;
        startIndex = richtextbox1.TextLength; // &lt;- Exception points here.
        // ...
    }
}</pre>

GeneralRe: Illegal cross thread exception in Invoke method Pin
yeah100018-Mar-10 1:33
yeah100018-Mar-10 1:33 
GeneralRe: Illegal cross thread exception in Invoke method Pin
yeah100031-Mar-10 6:16
yeah100031-Mar-10 6:16 
GeneralRe: Illegal cross thread exception in Invoke method Pin
AspDotNetDev31-Mar-10 9:27
protectorAspDotNetDev31-Mar-10 9:27 
GeneralRe: Illegal cross thread exception in Invoke method Pin
yeah100031-Mar-10 21:56
yeah100031-Mar-10 21:56 
GeneralRe: Illegal cross thread exception in Invoke method Pin
AspDotNetDev2-Apr-10 21:26
protectorAspDotNetDev2-Apr-10 21:26 
GeneralRe: Illegal cross thread exception in Invoke method Pin
yeah10005-Apr-10 1:39
yeah10005-Apr-10 1:39 
GeneralRe: Illegal cross thread exception in Invoke method Pin
AspDotNetDev5-Apr-10 20:27
protectorAspDotNetDev5-Apr-10 20:27 
GeneralRe: Illegal cross thread exception in Invoke method Pin
yeah10007-Apr-10 5:59
yeah10007-Apr-10 5:59 
GeneralRe: Illegal cross thread exception in Invoke method Pin
AspDotNetDev7-Apr-10 9:10
protectorAspDotNetDev7-Apr-10 9:10 
GeneralRe: Illegal cross thread exception in Invoke method Pin
yeah10007-Apr-10 10:01
yeah10007-Apr-10 10:01 
QuestionSub Containers Control Pin
Xmen Real 17-Mar-10 4:05
professional Xmen Real 17-Mar-10 4:05 
AnswerRe: Sub Containers Control Pin
Bernhard Hiller17-Mar-10 4:40
Bernhard Hiller17-Mar-10 4:40 
GeneralRe: Sub Containers Control Pin
Xmen Real 17-Mar-10 5:16
professional Xmen Real 17-Mar-10 5:16 
GeneralRe: Sub Containers Control Pin
Keith Barrow17-Mar-10 5:33
professionalKeith Barrow17-Mar-10 5:33 
GeneralRe: Sub Containers Control Pin
Xmen Real 17-Mar-10 7:00
professional Xmen Real 17-Mar-10 7:00 
Questionbind from XML Pin
Jassim Rahma17-Mar-10 3:52
Jassim Rahma17-Mar-10 3:52 
AnswerRe: bind from XML Pin
Kythen17-Mar-10 5:33
Kythen17-Mar-10 5:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.