Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to enable variable from form into class Timer
    text
    copied!<p>I have Main form class here:</p> <pre><code> public partial class Main : Form { public void button_Click(object sender, EventArgs e) { //here I want to call function runtime() from SchedulingTimer class // in oder to run afunc() every second or any Interval } public void afunc() { Message.Show(textbox1.Text); } } </code></pre> <p>And I have a Timer Class:</p> <pre><code>public class SchedulingTimer { public static void runtime() { Timer myTimer = new Timer(); myTimer.Elapsed += new ElapsedEventHandler(DisplayTimeEvent); myTimer.Interval =10000 ; // 1000 ms is one second myTimer.Start(); } public static void DisplayTimeEvent(object source, ElapsedEventArgs e) { //call function from main which have agrument textbox.Text afunc();//or any function which variable sended from Main form } } </code></pre> <p>But when I call <code>afunc</code> in <code>DisplayTimeEvent</code> method it has some error cause this is a <code>static</code> method so cannot access <code>textbox1.Text</code>. I think my code has some mistake.</p> <p><strong>UPDATE:</strong></p> <ul> <li>I set <code>myTimer.Enable= true</code> ,then, I click on <code>Button</code> but nothing happend. It seems <code>afunc()</code> doesn't work.</li> <li><p>create instance of Main method in DisplayTimeEvent. <code>Main objMain=new Main();</code> <code>objMain.afunc();</code> and there are some detail in afunc:</p> <pre><code> string keyw = cbkeyw.Text.ToString(); string link = cblink.Text.ToString(); if (radiobutton.Checked) { Yahoo yahoo = new Yahoo(); yahoo.RunProxyYahoo(proxylist, keyw, link, numPage, CountID); } else MessageBox.Show("Please choose Search Engine!"); </code></pre> <p>I call Yahoo Class in my afunc, that so really confused. When I click <code>Button</code>, it only show:<code>("Please choose Search Engine!");</code> event though I 've checked in <code>radiobutton</code> already </p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload