2 つのクラスがあります。1 つは Form1.cs と呼ばれ、もう 1 つは NoteThreader.cs と呼ばれ、両方のクラスの内容は次のとおりです。
Form1.cs:
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;
namespace HitMachine
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void updateText(string theText)
{
label1.Text = theText;
}
private void Form1_Load(object sender, EventArgs e)
{
XML.LoadMP3.loadFile(XML.XmlParser.ParseDocument("music"));
Threading.NoteThreader.createTimer();
}
}
}
NoteThreader.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace HitMachine.Threading
{
public class NoteThreader
{
public static Thread createTimer()
{
Thread t = new Thread(threadDeligation);
t.Start();
return t;
}
public static int time = 0;
static void threadDeligation()
{
for (; ; )
{
Form1 a = new Form1();
a.updateText(time);
time++;
}
}
}
}
コードは例外やエラーなしで実行されます。ただし、テキストは更新されません。メソッドを呼び出しているスレッドがテキストを更新しているスレッドとは異なるためだと思いますか?
私はそれを呼び出そうとしましたが、そうすることができませんでした。threadDeligation で MessageBox を実行したところ、うまくいきました。