Reputation: 775
I have a c# code with call function something like:
private void cmdCommand_Click(object sender, EventArgs e)
{
m_socClient.Close();
}
But now i want the m_socClient.Close();
function to be called after maybe 30 second. So is that possible?
Upvotes: 3
Views: 1684
Reputation: 101681
Yes, using async / await
feature:
private async void cmdCommand_Click(object sender, EventArgs e)
{
await Task.Delay(30000);
m_socClient.Close();
}
You can also do that using Thread.Sleep
but it will block your UI
thread and your window won't be responsive until the task is finished.
Upvotes: 11