GUIを更新するためのスレッドを取得しようとしていますが、イベントを使用するようにアドバイスされました。
具体的には、アプリケーションは以下のメソッドUpdateResult()でクロススレッドエラーを出します。私が提起するイベントはスレッドから提起されていると思います。したがって、メインスレッドで実行されているGUIを更新しようとしているときに問題が発生します。
私は間違って何をしましたか?
ありがとうダモ
C#コード
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
public delegate void UpdateScreenEventHandler();
namespace EventHandler
{
public partial class Form1 : Form
{
public static event UpdateScreenEventHandler _UpdateScreen;
public Form1()
{
InitializeComponent();
}
public void Form1_Load(object sender, EventArgs e)
{
// Add event handlers to Show event.
_UpdateScreen += new UpdateScreenEventHandler(UpdateResult);
}
private void button1_Click(object sender, EventArgs e)
{
// Thread the status check
Thread trd = new Thread(() => Threadmethod());
trd.IsBackground = true;
trd.Start();
}
private void Threadmethod()
{
// Invoke the event.
_UpdateScreen.Invoke();
}
private void UpdateResult()
{
textBox1.Text = "This Is the result";
MessageBox.Show(textBox1.Text);
}
}
}