How to create a stream in WinForms?

I need help creating a thread, C # winforms

private void button1_Click(object sender, EventArgs e) {
    Thread t=new Thread(new ThreadStart(Start)).Start();
}

public void Start() {
    MessageBox.Show("Thread Running");
}

I keep getting this message:

Cannot implicitly convert type 'void' to 'System.Threading.Thread

what to do with msdn documentation is not good

+5
source share
3 answers

This will work:

Thread t = new Thread (new ThreadStart (Start));
t.Start();

And this will work too:

new Thread (new ThreadStart(Start)).Start();

The MSDN documentation is good and correct, but you are doing it wrong. :) You are doing this:

Thread t = new Thread (new ThreadStart(Start)).Start();

So what you are doing here is trying to assign an object that is returned by the Start () method (which is invalid) to the Thread object; therefore an error message.

+14
source

Try to break it as such:

private void button1_Click(object sender, EventArgs e)
{
  // create instance of thread, and store it in the t-variable:
  Thread t = new Thread(new ThreadStart(Start));
  // start the thread using the t-variable:
  t.Start();
}

Thread.Start-method returns void(i.e. nothing), so when you write

Thread t = something.Start();

Start -, , t -variable. , , .

+2

.NET framework BackgroundWorker. , VisualEditor .

( ) , : http://dotnetperls.com/backgroundworker

+2

All Articles