Reputation: 77
How can I open a MessageBox , keep it open until a task finishes, and then close it.
I plan to insert a loading animation inside it.
I need to somehow make it that you cannot close it by clicking it, just through the code.
var t = Task.Run(() =>
{
MessageBox.Show("Loading!");
CycleValue = 0;
while (CycleValue < noOfCycles && buttonStartStop.Text == "Stop")
{
this.Invoke((MethodInvoker)delegate
{
gm.NextState();
CycleValue++;
if (CycleValue == noOfCycles)
{
buttonStartStop.Text = "Start";
buttonRandomise.Enabled = true;
buttonReset.Enabled = true;
}
});
}
});
Upvotes: 0
Views: 1479
Reputation: 3290
You need to create your own form/window that mimicks the look of the message box, but that you have more control over (eg implementing a closing event after a task has completed). A label and a couple of buttons shouldn't take too long, and will be useful in future projects!
Upvotes: 3
Reputation: 507
IF you want to show the busy cursor while an action is being performed on UI you can use -
Cursor.Current = Cursors.WaitCursor;
If you want to show an animation refer this
Upvotes: 0