Hi KumarThrainderMIND-0302,
When you use Task.Run to run a method, Task gets a thread from threadpool to run that method. So from the UI thread's perspective, it is "asynchronous" as it doesn't block UI thread.
So if you want to make form(poptest1) at the front so that the user can't click on other windows, there is no need to use Task.Run() in your code.
And async methods won't block the current thread, so you can use them from the UI thread directly.
Please refer to the following code:
Form2 f2 = new Form2();
private async void Button1_Click(object sender, EventArgs e)
{
await this.test2();
}
public async Task test2()
{
f2.BringToFront();
f2.TopMost = true;
f2.TopLevel = true;
f2.ShowDialog();
await Task.Delay(1000);
}
Best Regards,
Daniel Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.