private void WriteFile(object state) { FileParams fileparams = (FileParams)state; FileStream fs = new FileStream(fileparams.Content, FileMode.Create); byte[] dados = Encoding.UTF8.GetBytes(fileparams.Content); fs.Write(dados, 0, dados.Length); fs.Dispose(); }
// AULA 06.04 - Threading - 4 - thread pool private void button2_Click(object sender, EventArgs e) { // a ThreadPool, é uma thread de background, ou seja, quando a thread pai morre, as filhas morrem também // o que é o contrário de uma thread foreground, como vimos nas aulas anteriores ThreadPool.QueueUserWorkItem(WriteFile, new FileParams() { FilePath = "teste.txt", Content = FileParams.BuildContent() }); }