There is a need to pass a parameter to the stream. How to do it right?

  • 2
    You should not think in terms of threads, they are too low-level. Use Task , and everything will be easy and obvious. - VladD
  • I want to get the output is not convenient for me the code, and the "fast" - Alexander Puzanov
  • one
    Then do not use streams. Task.Run is executed on the thread pool, it does not need to create a new thread. Creating a new thread is a slow operation. - VladD
  • VladD, thanks. - Alexander Puzanov
  • You are welcome! Glad if it helps. - VladD

1 answer 1

I think this will do:

 private void RunAsync() { string param = "Hello world"; Task.Run(() => MethodWithParameter(param)); } private void MethodWithParameter(string param) { //Do smth } 

or so:

 var x_param = rawData; Task.Run(() => { // Do smth with 'x_param' });