c.sharp:非同期3_invoke
**以前のリビジョンの文書です**
- snippet.cs
await Task.Run(() =>
{
int Div =60;
for (int i = 30; i <= Div; i++)
{
int newY = (int)(point.Y * (i / (float)Div));
Point deltaPoint = new Point(point.X, newY);
webBrowser1.BeginInvoke(new Action(() =>
{
webBrowser1.Document.Window.ScrollTo(deltaPoint);
webBrowser1.Update();
}
));
Thread.Sleep(10);
this.webBrowser1.BeginInvoke(new Action(() => this.webBrowser1.Update()));
}
});
if (this.InvokeRequired)
{
this.BeginInvoke(new EventHandler<WaveInEventArgs>(OnDataAvailable), sender, e);
}
else
{
byte[] buffer = e.Buffer;
int bytesRecorded = e.BytesRecorded;
int bufferIncrement = waveIn.WaveFormat.BlockAlign;
for (int index = 0; index < bytesRecorded; index += bufferIncrement)
{
float sample32 = BitConverter.ToSingle(buffer, index);
sampleAggregator.Add(sample32);
}
}
/// <summary>
/// コンソールへ書き込み
/// </summary>
/// <param name="message"></param>
private void WriteConsole(string message, FontColors font_color = FontColors.NONE)
{
if (this.InvokeRequired)
{
// もし別スレッドの場合は、Invokeし、自分を呼び出す
richTextBox_Console.BeginInvoke(new Action(() =>
{
//リッチテキストボックスにフォーカスを移動
richTextBox_Console.Focus();
richTextBox_Console.AppendText(message + Environment.NewLine);
}));
return;
}
else
{
// 本当の処理
switch (font_color)
{
case FontColors.RED:
richTextBox_Console.ForeColor = Color.Red;
break;
case FontColors.BLUE:
richTextBox_Console.ForeColor = Color.Blue;
break;
case FontColors.YELLOW:
richTextBox_Console.ForeColor = Color.Yellow;
break;
case FontColors.GREEN:
richTextBox_Console.ForeColor = Color.Green;
break;
case FontColors.WHITE:
richTextBox_Console.ForeColor = Color.White;
break;
default:
richTextBox_Console.ForeColor = Color.Lime;
break;
}
//リッチテキストボックスにフォーカスを移動
richTextBox_Console.Focus();
richTextBox_Console.AppendText(message + Environment.NewLine);
}
}
c.sharp/非同期3_invoke.1538284769.txt.gz · 最終更新: 2018/09/30 05:19 by fifi