private void FormMain_Load(object sender, EventArgs e) { OpenFileDialog fd = new OpenFileDialog(); fd.Filter = "Текстовые файлы (.txt)|*.txt|Все файлы (*.*)|*.*"; fd.FilterIndex = 0; fd.CheckFileExists = false; MemoryFileHandler fileHandler = null; if (MemoryFileHandler.CheckFileExistInMemory()) { fileHandler = MemoryFileHandler.CreateInstance(fromMemory: true); } else { if (fd.ShowDialog() == DialogResult.OK) { fileHandler = MemoryFileHandler.CreateInstance(fd.FileName); } else { Close(); } } username = UsernameGenerator.CreateName(); writeHandler = new WriteHandler(username, fileHandler); readHandler = new ReadHandler(fileHandler); readHandler.NewMessages += ReadHandler_NewMessage; readHandler.StartChecking(); labelUsername.Text = "Имя: " + username; textBoxMessageText.MaxLength = Encoding.Unicode.GetMaxCharCount(MessageModel.COUNT_TEXT); }