Cau mam tady problem v casti polebtn[fir, two].Name = "jan"; kde mi to vyhodi vyjimku tady je preklad "Volající vlákno nemůže přistupovat tohoto objektu, protože jiné vlákno vlastní ji." prosim poradte, ja uz jsem z toho cely zmateny... diky
public partial class MainWindow : Window
{
private int q = 0;
private int w = 0;
private TcpListener list;
private Thread proc;
private string xxx;
public static int a = 10;
public static int b = 10;
private Mybutton button;
public void ukaz()
{
for (int i = 0; i < 10; i++)
{
for (int c = 0; c < 10; c++)
{
button = new Mybutton();
button.Margin = new Thickness(q, w, 0, 0);
button.X = c;
button.Y = i;
polebtn[c, i] = button;
button.Click += new RoutedEventHandler(button_Click);
button.Width = 20;
button.Height = 20;
canvas1.Children.Add(button);
q += 20;
}
q = 0;
w += 20;
}
}
private Mybutton[,] polebtn=new Mybutton[a, b];
public MainWindow()
{
InitializeComponent();
ukaz();
proc = new Thread(new ThreadStart(slys));
proc.Start();
}
public void slys()
{
IPAddress ip = IPAddress.Parse("127.0.0.1");
list = new TcpListener(ip, 2112);
list.Start();
TcpClient klient = list.AcceptTcpClient();
while (true)
{
string[] words;
NetworkStream str = klient.GetStream();
byte[] data = new byte[1024];
str.Read(data, 0, data.Length);
xxx = System.Text.Encoding.ASCII.GetString(data);
words = xxx.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
MessageBox.Show(words[1]);
int fir = Int32.Parse(words[0]);
int two = Int32.Parse(words[1]);
// polebtn[System.Convert.ToInt32(g), System.Convert.ToInt32(f)].BackColor = Color.Black;
polebtn[fir, two].Name = "jan"; // Tady je chyba
// proc.Start();
//list.Stop();
//klient.Close();
//str.Close();
}
}