Thread thread;
OtherMonitor monitor;
public void StartRecieveData()
{
System.Net.IPEndPoint iep = new IPEndPoint(IPAddress.Any, 999);
UdpClient client = new UdpClient(iep);
client.EnableBroadcast = true;
string data = null;
while (true)
{
byte[] byteData = client.Receive( ref iep);
data = Encoding.ASCII.GetString(byteData, 0, byteData.Length);
InsertDataToBase(data);
UpdateSecondMonitor(data);
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
monitor = new OtherMonitor();
monitor.Show();
thread = new Thread(new ThreadStart(StartRecieveData));
thread.IsBackground = true;
thread.Start();
}
InsertDataToBase(data) // function inserting record into Database
UpdateSecondMonitor(data) //- opened window on the second monitor, which should be updated
{
monitor.UpdateGrid();
}
и ошибка при попытке обновить сетку в окне монитора: вызывающий поток не может получить доступ к этому объекту, так как он принадлежит другому потоку
Я пытаюсь:
//thread = new System.Threading.Thread(
// new System.Threading.ThreadStart(
// delegate()
// {
// races.Dispatcher.Invoke(
// System.Windows.Threading.DispatcherPriority.Normal,
// new Action(delegate { StartRecieveData(); }));
// }
ДонНе знаю, как обновить данные в окне «Монитор».кто-то может знать ??