Created
May 4, 2017 14:18
-
-
Save JFRode/b44e4978e7b22d556351f2b6b7874bea to your computer and use it in GitHub Desktop.
Alterando text do Form a partir de uma Thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
namespace FormsSandbox | |
{ | |
public class ChecadorDeLabel | |
{ | |
public EventHandler<bool> _event; | |
public ChecadorDeLabel() | |
{ | |
} | |
public void ChecaSeContagemEhPar() | |
{ | |
int i = 0; | |
while (true) | |
{ | |
if (i % 2 == 0 ) | |
{ | |
_event.Invoke(this, true); | |
} | |
else | |
{ | |
_event.Invoke(this, false); | |
} | |
Thread.Sleep(5000); | |
i++; | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
namespace FormsSandbox | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
ChecadorDeLabel checador = new ChecadorDeLabel(); | |
checador._event += new EventHandler<bool>(MetodoQualquer); | |
Task.Run(()=> checador.ChecaSeContagemEhPar()); | |
} | |
private void MetodoQualquer(object sender, bool e) | |
{ | |
BeginInvoke((Action)delegate { labelTextoDeRodape.Visible = e; }); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment