메시지 상자를 표시하고 프로그램을 계속 진행하고이 메시지 상자에서 확인을 기다릴 필요가 없습니다. 할 수 있습니까?프로세스가 자동으로 계속 진행될 수있게 해주는 MessageBox
else
{
// Debug or messagebox the line that fails
MessageBox.Show("Cols:" + _columns.Length.ToString() + " Line: " + lines[i]);
}
메시지 상자를 표시하고 프로그램을 계속 진행하고이 메시지 상자에서 확인을 기다릴 필요가 없습니다. 할 수 있습니까?프로세스가 자동으로 계속 진행될 수있게 해주는 MessageBox
else
{
// Debug or messagebox the line that fails
MessageBox.Show("Cols:" + _columns.Length.ToString() + " Line: " + lines[i]);
}
첫째, 올바른 해결 방법은 일반 창 (또는 양식, 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();
당신이 빠른 - 및 - 더러운 솔루션을 원하는 경우에, 당신은 그냥 버리는 스레드에서 메시지 박스 호출 할 수 있습니다 :
Thread t = new Thread(() => MessageBox("lalalalala"));
t.SetApartmentState(ApartmentState.STA);
t.Start();
(확실하지 ApartmentState.STA
경우가 실제로 필요하다)
당신은 하나 개의 스레드 (메인 스레드) 처리를 할 것 등이 메시지 상자를 표시하는 데 사용되는이 작업을 달성하기 위해 멀티 스레딩을 사용해야합니다.
사용이
this.Dispatcher.BeginInvoke(new Action(() => { MessageBox.Show(this, "text"); }));
그것이 도움이되기를 바랍니다. 내가 MyProgram
라는 것에 코드의 나머지 계속할 수 있도록
using System.Threading;
static void MessageThread()
{
MessageBox.Show("Cols:" + _columns.Length.ToString() + " Line: " + lines[i]);
}
static void MyProgram()
{
Thread t = new Thread(new ThreadStart(MessageThread));
t.Start();
}
이것은 자신의 스레드에 MessageThread 기능을 시작합니다.
희망이 도움이됩니다.
//You need to add this if you don't already have it
using System.Threading.Tasks;
// 다음은 메인 스레드의 비동기를 실행하는 코드입니다.
Task.Factory.StartNew(() =>
{
MessageBox.Show("This is a message");
});
위임자 사용을 고려해 볼 수도 있습니다.
다음 snippits 제가
단지 마친 뭔가해야만 출신 -namespace YourApp
{
public partial class frmMain : Form
{
// Declare delegate for summary box, frees main thread from dreaded OK click
private delegate void ShowSummaryDelegate();
ShowSummaryDelegate ShowSummary;
/// <summary>
/// Your message box, edit as needed
/// </summary>
private void fxnShowSummary()
{
string msg;
msg = "TEST SEQUENCE COMPLETE\r\n\r\n";
msg += "Number of tests performed: " + lblTestCount.Text + Environment.NewLine;
msg += "Number of false positives: " + lblFalsePve.Text + Environment.NewLine;
msg += "Number of false negatives: " + lblFalseNve.Text + Environment.NewLine;
MessageBox.Show(msg);
}
/// <summary>
/// This callback is used to cleanup the invokation of the summary delegate.
/// </summary>
private void fxnShowSummaryCallback(IAsyncResult ar)
{
try
{
ShowSummary.EndInvoke(ar);
}
catch
{
}
}
/// <summary>
/// Your bit of code that wants to call a message box
/// </summary>
private void tmrAction_Tick(object sender, EventArgs e)
{
ShowSummary = new ShowSummaryDelegate(fxnShowSummary);
AsyncCallback SummaryCallback = new AsyncCallback(fxnShowSummaryCallback);
IAsyncResult SummaryResult = ShowSummary.BeginInvoke(SummaryCallback, null);
}
// End of Main Class
}
}
찬성 투표 1 라이너 – KingCronus
그름이 _next_는 메시지 루프 반복의 UI를 차단한다. OP는 메시지 상자를 완전히 비동기 적으로 원합니다. – Vlad