C# .NET - How to use a timer that never refreshes the page in C#

Asked By Austine on 20-Jun-12 04:18 AM
Hi , I want to know which is the best timer to use on a window forms application that will never affect or refres my page each time.
I have a Listview and a textbox on the form.
I am searching a listview using the textBox and each time a user is still search for a name in the listview , the filtered results disppear when the timer on the page runs and refreshes my page.
I want this time to work as a background timer that runs but never affect my winform pages so that the user can be able to search the listview while the timer is still running.
Please help me with the best solutions.
Thank you
Ravi Maurya replied to Austine on 20-Jun-12 04:22 AM

If you want simple timer control than you can make use of javascript here is the like where you can find sample peace of code



Or if you want count down timer, Please check the below sample:

<div id="timelabel"></div>
 <script type="text/javascript">
var leave =<%=seconds %>;
var interv=setInterval(CounterTimer,1000);
function CounterTimer()
var day = Math.floor(leave / ( 60 * 60 * 24))
var hour = Math.floor(leave / 3600) - (day * 24)
var minute = Math.floor(leave / 60) - (day * 24 *60) - (hour * 60)
var second = Math.floor(leave) - (day * 24 *60*60) - (hour * 60 * 60) - (minute*60)
hour=hour<10 ? "0" + hour : hour;
minute=minute<10 ? "0" + minute : minute;
second=second<10 ? "0" + second : second;
var remain=day + " days   "+hour + ":"+minute+":"+second;

Now here is the server side code

public double seconds;
  protected void Page_Load(object sender, EventArgs e)
  seconds = (GetEndTime() - GetStartTime()).TotalSeconds;
  private DateTime GetStartTime()
  return DateTime.Now;
  private DateTime GetEndTime()
  return new DateTime(2008, 7, 23, 8, 10, 0);

Hope this will help you.
Austine replied to Ravi Maurya on 20-Jun-12 04:44 AM
Hi , I want this in C# window form
Lalit M replied to Austine on 20-Jun-12 05:48 AM
If you want to use client side timer then use this link

Jitendra Faye replied to Austine on 20-Jun-12 09:18 AM
Put Timer control inside updatepanel,  it will update only content  of UpdatePanel.

like this-

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
         <asp:Timer ID="Timer1" runat="server" Enabled="true" Interval="10" OnTick="Timer1_Tick">

        other controls

Austine replied to Lalit M on 20-Jun-12 09:18 AM
Hi ,   Can somebody help me on This

Still not working 

Thank you
Lalit M replied to Austine on 21-Jun-12 01:08 AM
Check this code

private void Form1_Load(object sender, EventArgs e)
      Timer MyTimer = new Timer();
      MyTimer.Interval = (45 * 60 * 1000); // 45 mins
      MyTimer.Tick += new EventHandler(MyTimer_Tick);

    private void MyTimer_Tick(object sender, EventArgs e)
      MessageBox.Show("The form will now be closed.", "Time Elapsed");
Austine replied to Lalit M on 21-Jun-12 06:05 AM
Hi this works quite well and is what i have currently but now it still refreshes the listview in my program.
When i type a letter in the textBox that i want to search for the user, it refreshes the page and the filtered items disappears.
I really need a solution that works but right now is not working.

Thank you.
Lalit M replied to Austine on 21-Jun-12 07:18 AM
you are Welcome :)