回答編集履歴
1
追記
answer
CHANGED
@@ -4,4 +4,62 @@
|
|
4
4
|
ご提示されていないコードに原因があると予想します。
|
5
5
|
|
6
6
|
例えば、Message_textBoxをサブスレッドで生成しているようなことはないでしょうか?
|
7
|
-
ご提示されているソースを含むコントロール(Form1?)を生成したスレッドとは別のスレッドでMessage_textBoxを生成していた場合、そのようなエラーが出ます。
|
7
|
+
ご提示されているソースを含むコントロール(Form1?)を生成したスレッドとは別のスレッドでMessage_textBoxを生成していた場合、そのようなエラーが出ます。
|
8
|
+
|
9
|
+
---
|
10
|
+
【追記】
|
11
|
+
Visual Studio 2017 Communityで、やってみました。
|
12
|
+
Form1にはMessage_textBoxだけ貼り付けてます。
|
13
|
+
起動後、約3秒(300を3000に変えてます)でMessage_textBoxにtestと表示されます。
|
14
|
+
|
15
|
+
```C#
|
16
|
+
using System;
|
17
|
+
using System.Collections.Generic;
|
18
|
+
using System.ComponentModel;
|
19
|
+
using System.Data;
|
20
|
+
using System.Drawing;
|
21
|
+
using System.Linq;
|
22
|
+
using System.Text;
|
23
|
+
using System.Threading;
|
24
|
+
using System.Threading.Tasks;
|
25
|
+
using System.Timers;
|
26
|
+
using System.Windows.Forms;
|
27
|
+
|
28
|
+
namespace WindowsFormsApp2
|
29
|
+
{
|
30
|
+
public partial class Form1 : Form
|
31
|
+
{
|
32
|
+
public Form1()
|
33
|
+
{
|
34
|
+
InitializeComponent();
|
35
|
+
// this.settingsData = Settings.Load();
|
36
|
+
timer = new System.Timers.Timer();
|
37
|
+
timer.Interval = 3000; // インターバル
|
38
|
+
timer.Elapsed += TimerHandler;
|
39
|
+
timer.AutoReset = true; // false:最初の1回だけ実行
|
40
|
+
//timer.Enabled = true; // timer.Start()と同じ
|
41
|
+
timer.Start();
|
42
|
+
}
|
43
|
+
private System.Timers.Timer timer = null;
|
44
|
+
|
45
|
+
private void TimerHandler(object sender, ElapsedEventArgs e)
|
46
|
+
{
|
47
|
+
Thread t = new Thread(new ThreadStart(anotherThread));
|
48
|
+
t.Start();
|
49
|
+
}
|
50
|
+
|
51
|
+
delegate void delegate1(String detail_data);
|
52
|
+
|
53
|
+
void setFocus(String detail_data)
|
54
|
+
{
|
55
|
+
Message_textBox.Text = detail_data;
|
56
|
+
Message_textBox.Focus();
|
57
|
+
}
|
58
|
+
|
59
|
+
void anotherThread()
|
60
|
+
{
|
61
|
+
Invoke(new delegate1(setFocus), "test");
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
```
|