Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将messagebox消息移动到列表_C#_.net_Winforms_C# 4.0_Windows Forms Designer - Fatal编程技术网

C# 如何将messagebox消息移动到列表

C# 如何将messagebox消息移动到列表,c#,.net,winforms,c#-4.0,windows-forms-designer,C#,.net,Winforms,C# 4.0,Windows Forms Designer,我有一个经常生成状态消息的应用程序。我正在将所有这些消息打印到消息框中。我想使用列表框或多行文本框,而不是使用消息框。我该如何进行 void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) { publishstatusTextbox.Items.Insert(0, DateTime.Now.ToString("hh:mm:ss:fff") + "MessageID="); } 我遇到了以下

我有一个经常生成状态消息的应用程序。我正在将所有这些消息打印到消息框中。我想使用列表框或多行文本框,而不是使用消息框。我该如何进行

void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
{
    publishstatusTextbox.Items.Insert(0, DateTime.Now.ToString("hh:mm:ss:fff") + "MessageID=");
}
我遇到了以下异常

跨线程操作无效“publishstatusListbox”是从创建它的线程以外的线程访问的


您可能希望这样做,将所有错误分组,然后将它们全部放在一个消息框中

var errors = new List<string>();

try
{ 
    //your code here 
}
catch(Exception ex) {
    errors.Add(ex.InnerException.ToString());
}

var sb = new StringBuilder();
foreach (var errorMessage in errors)
{   
    sb.AppendLine(errorMessage);
}

if (errors.Count > 0)
{
    MessageBox.Show(sb.ToString(), "Errors Present", MessageBoxButton.OK, MessageBoxImage.Error);
}
var errors=newlist();
尝试
{ 
//你的代码在这里
}
捕获(例外情况除外){
errors.Add(例如InnerException.ToString());
}
var sb=新的StringBuilder();
foreach(var errorMessage in errors)
{   
某人追加电话(错误信息);
}
如果(errors.Count>0)
{
Show(sb.ToString(),“存在错误”,MessageBoxButton.OK,MessageBoxImage.Error);
}

在UI线程中运行此代码可能存在重复