 <p>Your code isn't compilable. Here is the reasons:</p> <ol> <li>The conditions must be placed into some method</li> <li>The declaration of event handler must be moved out from the condition scope</li> </ol> <p>Here is the workable code:</p> <pre><code>namespace WindowsFormsApplication1 { public partial class Form1 : Form { private int flag; FileSystemWatcher watcher = new FileSystemWatcher(); public Form1() { InitializeComponent(); watcher.Path = @"C:\"; watcher.Filter = "test.txt"; watcher.Changed += watcher_Changed; watcher.EnableRaisingEvents = true; } private void SetFlag() { FileInfo info = new FileInfo("c:\\test.txt"); if (info.Length &gt; 0) flag= 1; } private void CheckFlag() { if(flag==1) { button1.PerformClick(); } } private void button1_Click(object sender, EventArgs e) { //Code for Redirection to New Form } void watcher_Changed(object sender, FileSystemEventArgs e) { SetFlag(); CheckFlag(); } } } </code></pre> <p>And now you can call method <code>SetFlag()</code> to set flag. And use method <code>CheckFlag()</code> to check flag. In this example I use <code>FileSystemWatcher</code> to catch all file changes and call <code>SetFlag()</code> and <code>CheckFlag()</code> inside the handler of event <code>Changed</code></p> <p>Instead of <code>button1.PerformClick()</code> you can use <code>button1_Click(this, EventArgs.Empty)</code></p>