-2

I have a method

    public void splitXmlFile()
    {
        string[] line = Regex.Split(inputText.Text, "\n+");
        progressStt.Maximum = line.Length;
        progressStt.Step = 1;
        foreach (string q in line)
        {
            progressStt.performStep();
            if (Regex.IsMatch(q, "<[^>]*>"))
            {
                if (Regex.IsMatch(Regex.Split(q, "<[^>]*>")[0], @"\s"))
                {
                }
                string[] gettag = Regex.Split(q, "(<.*?>)|(.+?(?=<|$))");
                foreach (var gettag1 in gettag)
                {
                    if (Regex.IsMatch(gettag1, "<[^>]*>"))
                    {
                    }
                    else
                    {
                        if (Regex.IsMatch(gettag1, @"\w"))
                            listXml.Add(gettag1);
                    }
                }
            }
            else
            {
                if (Regex.IsMatch(q, @"\w"))
                    listXml.Add(q);
            }
        }
        progressStt.Value = 0;
    }

Create new thread:

Thread t1= new Thread(new ThreadStart(splitXmlFile)); t1.Start();

But when i start i had i exception in line:

string[] line = Regex.Split(inputText.Text, "\n+");

I think it can come in:

progressStt.Maximum = line.Length;
            progressStt.Step = 1;
progressStt.performStep();
progressStt.Value = 0;

I can't fix it's, What should i do??

John Saunders
  • 160,644
  • 26
  • 247
  • 397
hazymnc
  • 107
  • 1
  • 10
  • 5
    Don't do that. You should use an XML parser. – SLaks Jan 10 '14 at 18:42
  • 1
    You should probably use an XML parser instead of half-assing your own. There are at least a dozen things you'll miss trying to do this with regexes alone. – cHao Jan 10 '14 at 18:42
  • 2
    There are **hundreds** of questions about this exception message. No point in adding another one, put the message text in the Search box or use Google. – Hans Passant Jan 10 '14 at 18:43
  • 1
    InvalidOperationException was unhandled: Cross-thread operation not valid: Control 'inputText' accessed from a thread other than the thread it was created on. – hazymnc Jan 10 '14 at 18:47
  • What are you trying to do?....I love regex, but I think this can be done in a more effective way. – ΩmegaMan Jan 10 '14 at 18:57

1 Answers1

0

inputText.Text resides on the GUI thread. You need to pass in that data before the thread starts such as:

 newThread.Start(inputText.Text);

and then getting the value within the threading method. See MSDN Thread.Start.

I ran into similar and wrote an article on it entitled C# WPF: Linq Fails in BackgroundWorker DoWork Event

ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122