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 :: asp.net throw unauthorized exception 
Csharp :: How do I remove all non alphanumeric characters from a string? 
Csharp :: unity how to reorder a list 
Csharp :: game object set exact position unity 
Csharp :: aabb collision with direction 
Csharp :: how to add a delay in csharp 
Csharp :: c# serialize to xml 
Csharp :: c# close 1 form open another form 
Csharp :: loan calculator using windows forms in c# code 
Csharp :: unity get a position inside sphere 
Csharp :: unity 2d looka tt mouse 
Csharp :: c#: how to request for admin priviledge 
Csharp :: .net core authorizationhandlercontext 
Csharp :: cinemachine namespace not working 
Csharp :: get enum by index c# 
Csharp :: convert string to short c# 
Csharp :: Unity asset storre download forlder 
Csharp :: how to add reference to rigidbody 2d 
Csharp :: c# return list 
Csharp :: unity round to x decimals 
Csharp :: c# clear a textbox 
Csharp :: button not working unity 
Csharp :: T SQL Format GetDate() 
Csharp :: void to action c# 
Csharp :: c# update value in a json file 
Csharp :: difference between while and do while in c# 
Csharp :: c# how to refreshyour bindingsource 
Csharp :: dropdown wpf 
Csharp :: c# sqlite query 
Csharp :: how to display doubles with trailing zeros in c# 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =