我想要一个消息框显示,程序只是继续,而不是等我在这个消息框上单击确定.可以吗?
else
{
// Debug or messagebox the line that fails
MessageBox.Show("Cols:" + _columns.Length.ToString() + " Line: " + lines[i]);
}
Run Code Online (Sandbox Code Playgroud)
//You need to add this if you don't already have it
using System.Threading.Tasks;
Run Code Online (Sandbox Code Playgroud)
//然后这是你的代码将运行主线程的异步;
Task.Factory.StartNew( () =>
{
MessageBox.Show("This is a message");
});
Run Code Online (Sandbox Code Playgroud)
首先,正确的解决方案是将消息框替换为普通窗口(或表单,如果您使用的是 winforms)。那很简单。示例(WPF)
<Window x:Class="local:MyWindow" ...>
<Grid>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"
Text="{Binding}" />
<Button HorizontalAlignment="Right" VerticalAlignment="Bottom"
Click="SelfClose">Close</Button>
</Grid>
</Window>
...
class MyWindow : Window
{
public MyWindow(string message) { this.DataContext = message; }
void SelfClose(object sender, RoutedEventArgs e) { this.Close(); }
}
...
new MyWindow("Cols:" + _columns.Length.ToString() + " Line: " + lines[i]).Show();
Run Code Online (Sandbox Code Playgroud)
如果您想要一个快速而肮脏的解决方案,您可以从一次性线程中调用消息框:
Thread t = new Thread(() => MessageBox("lalalalala"));
t.SetApartmentState(ApartmentState.STA);
t.Start();
Run Code Online (Sandbox Code Playgroud)
(不确定是否ApartmentState.STA真的需要)
| 归档时间: |
|
| 查看次数: |
7685 次 |
| 最近记录: |