3
Answers

Execute my code while the program is running or the form is opened

Bahar Jalali

Bahar Jalali

13y
1.6k
1
hi
i want my code execute always , while my program is running or while my form is opened

i use if form is already open but it work only once and don't work continuously!
like this:

/////////////////////

public void Form1_Load(object sender, EventArgs e)
  {
  FormCollection fc = Application.OpenForms;

  foreach (Form frm in fc)
  {
  //iterate through
  // here is my code
 
  }
}

/////////////////////

is it true that check it in form load?
could you help me ?


Answers (3)
0
Sam Hobbs

Sam Hobbs

NA 28.7k 1.3m 13y
I assume this is related to your other thread. It is still not clear if the "Save As" dialog is in your application (process) or in a different process.
0
Bahar Jalali

Bahar Jalali

NA 153 259.8k 13y
i use timer but it enters every program on windows that mouse go move on!

because the command <sendkey.send("{ENTER}")> is in the timer tick event!

and it execute this command on all programs.

i thinks when i put the code in a timer thick event, it can't detect "Save Az" window ! but i want when it detect a save as window then enters it.

any idea?!
0
Zoran Horvat

Zoran Horvat

NA 5.7k 516.2k 13y
Bahar,

Use timer to execute code in background:

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);

    _timer = new Timer();
    _timer.Interval = 1000;
    _timer.Tick += new EventHandler(TimerTick);
    _timer.Start();

}

void TimerTick(object sender, EventArgs e)
{
    Text = DateTime.Now.ToLongTimeString();
}

private System.Windows.Forms.Timer _timer;

Your code should go into TimerTick method. This method will be executed on a UI thread so you're free to modify form's contents at will. Timer will execute once every second. You can change this interval by modifying the line:

_timer.Interval = 1000;

Interval is measured in milliseconds.


Zoran