You need to pass the vyvod variable to the temp function.

using System; using System.Collections.Generic; using System.Windows.Forms; using System.Text; using System.Threading; using xNet; namespace pogoda { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } public void Button1Click(object sender, EventArgs e) { var request = new HttpRequest(); request.AllowAutoRedirect = true; request.CharacterSet = Encoding.GetEncoding("UTF-8"); request.UserAgent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36 OPR/34.0.2036.25"; string vyvod = request.Get("http://pogoda.tut.by/city/minsk").ToString(); // Data is geting. start multithear Thread th = new Thread(temp); th.Start(); } public void MainFormLoad(object sender, EventArgs e) { } public void temp(){ string temp = vyvod.Substring("<span class=\"temp-i\">", "</span>"); temp = temp.Replace("&deg;", "°"); label2.Text = temp; } } } 
  • you have a variable vyvod not declared. must be string vyvod = ... and the string with Substring is not compiled. - PashaPash
  • corrected a bit. Are you xNet hooked up? - Vlad
  • a, there is an extension method. well ok, the answer doesn't depend on it anyway :) - PashaPash
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

Through the closure:

 Thread th = new Thread(() => temp(vyvod)); th.Start(); public void temp(string vyvod) { } 

only with changing the value of label2.Text from the background thread, you will have problems - see the Question Working with controls from the background stream .

  • with closures may be surprises. I added an example to my answer. - Stack
  • @Stack is probably not a surprise, but one of the examples why you cannot use one variable for two different purposes :) - PashaPash
  • I would say an illustration that the value of a variable can change . - VladD
  • @VladD is just a feature of closures. but not a reason to abandon them, as in the example ru.stackoverflow.com/a/480646/177221 - PashaPash
  • @PashaPash: How to refuse it? I can't live without them! - VladD

Instead of Thread it is better to use Task and async \ await.
And in Thread you can pass a link to the object - like this:

 var t = new Thread(handler); t.Start(data); ... void handler(object o) { var data = (DataType)o; // ... } 

You can use a closure, but because of this there may be surprises (example below at the end of the answer).

 var vyvod = ... var t = new Thread(() => temp(vyvod)); t.Start(); ... public void temp(string vyvod) { } 

An example of a surprise with closures.
If the variable that is in the closure, after starting the stream and before using it in the stream, will be changed, then we get not what we expected.

 var m = new ManualResetEvent(false); var s = "123"; var t = new Thread(() => { m.WaitOne(); // - поток может запуститься не сразу temp(s); // s в замыкании. и казалось бы, что temp получит "123" }); t.Start(); // запускаем поток s = "321"; // меняем значение m.Set(); static void temp(string s) { Console.WriteLine(s); // выводит "321" } 

Another closure example here .