MessageBox that allows a process to continue automatically

.net, c#, ssis

Solution

First, the correct solution would be to replace the messagebox with a plain window (or form, if you are using winforms). That would be quite simple. Example (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();

If you want a quick-and-dirty solution, you can just call the messagebox from a throwaway thread:

Thread t = new Thread(() => MessageBox("lalalalala"));
t.SetApartmentState(ApartmentState.STA);
t.Start();

(not sure if `ApartmentState.STA` is actually needed)

Problem

I would like a message box to be displayed and the program to just continue and not wait for me to click ok on this message box. Can it be done ? ``` else { // Debug or messagebox the line that fails MessageBox.Show("Cols:" + _columns.Length.ToString() + " Line: " + lines[i]); } ```

Original source