Click here to Skip to main content
16,008,954 members
Home / Discussions / C#
   

C#

 
GeneralRe: (Rich)TextBox problem! Pin
OlivierPD27-Sep-11 6:31
OlivierPD27-Sep-11 6:31 
Questionplz give guideline.. Pin
Pragya727-Sep-11 1:22
Pragya727-Sep-11 1:22 
AnswerRe: plz give guideline.. Pin
Richard MacCutchan27-Sep-11 1:33
mveRichard MacCutchan27-Sep-11 1:33 
GeneralRe: plz give guideline.. Pin
Pragya730-Sep-11 0:16
Pragya730-Sep-11 0:16 
AnswerRe: plz give guideline.. Pin
BobJanova27-Sep-11 1:39
BobJanova27-Sep-11 1:39 
AnswerRe: plz give guideline.. Pin
Pete O'Hanlon27-Sep-11 3:02
mvePete O'Hanlon27-Sep-11 3:02 
AnswerRe: plz give guideline.. Pin
RichardGrimmer28-Sep-11 6:25
RichardGrimmer28-Sep-11 6:25 
QuestionC# InvokeRequired into WPF Pin
iresh8827-Sep-11 0:53
iresh8827-Sep-11 0:53 
Hi, i'm working on a 2 player board game which plyer 1 runs in C# and player 2 in Java.... i'm using thread to pass data using XMLserilization and JAXB Marshaller in java.

I want to do C# part in WPf and its gives exception

"invalidOperationException" "The calling thread cannot access this object because a different thread owns it"

heres my c# code and wpf... someone pls help....




**************************CORRECT c# CODING**************************
C#
private void button1_Click(object sender, EventArgs e)
        {
            GameData g = new GameData();

            g.Turn = true;
            g.PlayerValue = int.Parse(textBox1.Text);

                FileStream fs = new FileStream(@"C:\Users\IsH\Desktop\Podi wadak\GameData\GameData.xml", FileMode.Create); 
            XmlSerializer xs = new XmlSerializer(typeof(GameData)); 
            xs.Serialize(fs, g);
            fs.Close(); 

            button1.Enabled = false;

            Thread.Sleep(2000);

            Thread t2 = new Thread(new ThreadStart(getData));
            t2.Start();
        }




getdata metherd

C#
public void getData()
      {
          GameData g = null;

          do
          {
              try
              {
                  FileStream fs = new FileStream(@"C:\Users\IsH\Desktop\Podi wadak\GameData\GameData.xml", FileMode.Open);


                  XmlSerializer xs = new XmlSerializer(typeof(GameData));
                  g = (GameData)xs.Deserialize(fs);
                  fs.Close();

                  Thread.Sleep(2000);
              }
              catch (Exception ex)
              {

              }
          } while (g.Turn != false);


          if (this.InvokeRequired)
          {
              callMethod m = new callMethod(getData);
              this.Invoke(m);
          }
          else
          {
              textBox2.Text = "" + g.PlayerValue;
              button1.Enabled = true;
          }

      }

*********************************************************************
here is my wpf code wich gives me the error



C#
private void button1_Click(object sender, RoutedEventArgs e)
        {

            GameData g = new GameData();

            g.Turn = true;
            g.PlayerValue = int.Parse(textBox1.Text);

            FileStream fs = new FileStream(@"C:\Users \IsH\Desktop\Podi wadak\WpfApplication1\GameData\GameData.xml", FileMode.Create);
            XmlSerializer xs = new XmlSerializer(typeof(GameData)); 
            xs.Serialize(fs, g);
            fs.Close();

            button1.IsEnabled = false; 

            Thread.Sleep(2000);

            Thread t2 = new Thread(new ThreadStart(getData));
            t2.Start();
        }



****************Get DATA Method that gives the error********************

C#
public void getData()
        {
            GameData g = null;

            do
            {
                try
                {
                    FileStream fs = new FileStream(@"C:\Users\IsH\Desktop\Podi wadak\WpfApplication1\GameData\GameData.xml", FileMode.Open);
                    

                    XmlSerializer xs = new XmlSerializer(typeof(GameData)); 
                    g = (GameData)xs.Deserialize(fs);
                    fs.Close();

                    Thread.Sleep(2000);
                }
                catch (Exception ex)
                {

                }
            } while (g.Turn != false);


            if (this.Dispatcher.Thread == Thread.CurrentThread)
            {
                callMethod m = new callMethod(getData);
                this.Dispatcher.BeginInvoke(m); 
            }
            else
            {
//###################ERROR COMES HERE####################
                textBox2.Text = "" + g.PlayerValue;
                button1.IsEnabled = true;
            }

        }

AnswerRe: C# InvokeRequired into WPF Pin
BobJanova27-Sep-11 1:36
BobJanova27-Sep-11 1:36 
GeneralRe: C# InvokeRequired into WPF Pin
Ian Shlasko27-Sep-11 2:57
Ian Shlasko27-Sep-11 2:57 
GeneralRe: C# InvokeRequired into WPF Pin
iresh8827-Sep-11 4:28
iresh8827-Sep-11 4:28 
GeneralRe: C# InvokeRequired into WPF Pin
BobJanova27-Sep-11 5:15
BobJanova27-Sep-11 5:15 
Questionhow to identify my screen data? Pin
neodeaths26-Sep-11 23:46
neodeaths26-Sep-11 23:46 
AnswerRe: how to identify my screen data? Pin
Pete O'Hanlon27-Sep-11 0:19
mvePete O'Hanlon27-Sep-11 0:19 
GeneralMy vote of one Pin
Eddy Vluggen28-Sep-11 7:29
professionalEddy Vluggen28-Sep-11 7:29 
GeneralRe: My vote of one Pin
Pete O'Hanlon28-Sep-11 7:57
mvePete O'Hanlon28-Sep-11 7:57 
GeneralRe: My vote of one Pin
Eddy Vluggen28-Sep-11 8:15
professionalEddy Vluggen28-Sep-11 8:15 
GeneralRe: My vote of one Pin
Pete O'Hanlon28-Sep-11 8:26
mvePete O'Hanlon28-Sep-11 8:26 
GeneralRe: My vote of one Pin
Eddy Vluggen28-Sep-11 9:53
professionalEddy Vluggen28-Sep-11 9:53 
AnswerRe: how to identify my screen data? Pin
Eddy Vluggen27-Sep-11 6:15
professionalEddy Vluggen27-Sep-11 6:15 
GeneralRe: how to identify my screen data? Pin
neodeaths27-Sep-11 20:46
neodeaths27-Sep-11 20:46 
GeneralRe: how to identify my screen data? Pin
Eddy Vluggen28-Sep-11 7:33
professionalEddy Vluggen28-Sep-11 7:33 
GeneralRe: how to identify my screen data? Pin
Pete O'Hanlon28-Sep-11 8:11
mvePete O'Hanlon28-Sep-11 8:11 
Questionquestion about programming for interacting with my desktop controls Pin
neodeaths26-Sep-11 23:43
neodeaths26-Sep-11 23:43 
AnswerRe: question about programming for interacting with my desktop controls Pin
André Kraak27-Sep-11 2:06
André Kraak27-Sep-11 2:06 

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.