回答編集履歴

1

ソースコードを修正

2024/08/02 11:51

投稿

jmdajmw
jmdajmw

スコア346

test CHANGED
@@ -24,7 +24,7 @@
24
24
 
25
25
  private static object lockObject = new object();
26
26
  private static int Counter = 0;
27
- delegate void delegate1();
27
+ public delegate void DelegateUpdateText();
28
28
  private static Timer timer;
29
29
 
30
30
  private void Form1_Load(object sender, EventArgs e)
@@ -42,13 +42,16 @@
42
42
  }
43
43
  void TimerCallback(object state)
44
44
  {
45
- delegate1 d = new delegate1(updateText);
46
- d();
45
+ updateText();
47
46
  }
48
47
 
49
48
  private void updateText()
50
49
  {
50
+ this.Invoke(new DelegateUpdateText(this.OnUpdateText));
51
+ }
52
+ private void OnUpdateText()
53
+ {
51
- lock(lockObject)
54
+ lock (lockObject)
52
55
  {
53
56
  Counter++;
54
57
  label1.Text = Counter.ToString();// ソケット通信の受信の代わり