Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# thread sleep

Thread.Sleep(2000); //in ms
Comment

c# thread wait


public class Form1 : Form
{
    int _count;

    void ButtonClick(object sender, EventArgs e)
    {
        ThreadWorker worker = new ThreadWorker();
        worker.ThreadDone += HandleThreadDone;

        Thread thread1 = new Thread(worker.Run);
        thread1.Start();

        _count = 1;
    }

    void HandleThreadDone(object sender, EventArgs e)
    {
        // You should get the idea this is just an example
        if (_count == 1)
        {
            ThreadWorker worker = new ThreadWorker();
            worker.ThreadDone += HandleThreadDone;

            Thread thread2 = new Thread(worker.Run);
            thread2.Start();

            _count++;
        }
    }

    class ThreadWorker
    {
        public event EventHandler ThreadDone;

        public void Run()
        {
            // Do a task

            if (ThreadDone != null)
                ThreadDone(this, EventArgs.Empty);
        }
    }
}

Comment

PREVIOUS NEXT
Code Example
Csharp :: how to get element dictionary key in c# by index 
Csharp :: c# regex number only 
Csharp :: remove session in dotnet core 
Csharp :: orderbyascending c# 
Csharp :: c# générer un nombre aléatoire 
Csharp :: stop sound in unity 
Csharp :: visual studio windows form exit button 
Csharp :: monogame fullscreen 
Csharp :: unityWebRequest get returned data 
Csharp :: object list to csv c# 
Csharp :: c# string newline 
Csharp :: ask for administrative permission 
Csharp :: pass datatable to stored procedure c# dapper 
Csharp :: transfer ownership photon2 
Csharp :: how to take user input in string in c# 
Csharp :: c# 2-dimensional array sort 
Csharp :: c# split string for all blank character 
Csharp :: how to have is trigger on but also have collisions 
Csharp :: get distinct from datatable c# 
Csharp :: c# connect to mongodb 
Csharp :: json get request c# 
Csharp :: waitforseconds unity 
Csharp :: C# get string as stream 
Csharp :: select a object from list based on a value csharp 
Csharp :: read xml file c# 
Csharp :: c# countdown timer menutes 
Csharp :: how to pass class type to method c# 
Csharp :: c# read file current directory 
Csharp :: slider.onchanged in unity 
Csharp :: get random color 32 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =