I can not throw in the string array data from the file.
public partial class Settings : Form { public static string Server { get; set; } public static string DataBase { get; set; } public static string Login { get; set; } public static string Password { get; set; } public static MySqlSslMode SslMode { get; set; } public static int Port { get; set; } string[] str=new string[6]; public Settings() { InitializeComponent(); } private void Settings_Load(object sender, EventArgs e) { comboBox1.DataSource = Enum.GetValues(typeof(MySqlSslMode)); string[] str = new string[6]; FillArrStringAsync(); label7.Text = str[0]; label8.Text = str[1]; label12.Text = str[2]; label11.Text = str[3]; label10.Text = str[4]; label9.Text = str[5]; } public string FillArrString() { string[] str = new string[6]; using (StreamReader reader = new StreamReader(@"SettingsProgram.txt", Encoding.UTF8)) { int tempVar = 0; while (!reader.EndOfStream) { str[tempVar] = reader.ReadLine(); tempVar++; } } return String.Concat(str); } public async void FillArrStringAsync() { await Task.Factory.StartNew(FillArrString); } private void button2_Click(object sender, EventArgs e) { Close(); } private void button1_Click(object sender, EventArgs e) { if (textBox1.Text != "" && textBox2.Text != "" && textBox5.Text != "" && maskedTextBox1.Text != "" && comboBox1.Text != "") { Server = textBox1.Text; DataBase = textBox5.Text; Login = textBox2.Text; Password = textBox3.Text; SslMode = (MySqlSslMode)Enum.Parse(typeof(MySqlSslMode), comboBox1.Text); Port = Convert.ToInt32(maskedTextBox1.Text); using (StreamWriter writer = new StreamWriter(@"SettingsProgram.txt", false, Encoding.UTF8)) { writer.Write(Server + "\r\n"); writer.Write(DataBase + "\r\n"); writer.Write(Login + "\r\n"); writer.Write(Password + "\r\n"); writer.Write(SslMode.ToString() + "\r\n"); writer.Write(Port.ToString() + "\r\n"); writer.Close(); } } else { MessageBox.Show("Заполните все поля!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } When debugging, we get data from the file through FillArrStringAsync, everything works. But when I try to fill in labels with these values when the form is loaded, it is not filled in, just an empty string. Who knows why this could be? I also noticed that when I use the FillArrString function through debug, all the values skip over me, but the output I get is still an empty array.
str, which you do not fill. And you fill in a completely different local variable in a different method, but just with the same name - tym32167