C# Winform Auto Refresh: Every 5 Minutes [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a C# WinForm application that I need to be refreshed every 5 minutes.
I have looked into Background Worker as well as, a Timer Class.
I was just wondering what is the best way to get main form refreshed so user updates can be displayed without having to close the application and reopening it.

that is called polling , you can use Timer control to do that.
Step 1: You need to Subscribe to the Timer Tick event.
Step 2: Set the Interval property of the Timer to 300000 milliseconds for raising the event for every 5 Minutes.
Step 3: In Tick Event Handler just do whatever you want to perform.
Step 4: you can Call the timer1.Stop() method whenever you want to stop the timer.
Note : if you don't stop the timer it becomes infinite.
if you want to stop the timer you can call timer1.Stop();
System.Windows.Forms.Timer timer1 = new System.Windows.Forms.Timer();
timer1.Interval=300000;//5 minutes
timer1.Tick += new System.EventHandler(timer1_Tick);
timer1.Start();
private void timer1_Tick(object sender, EventArgs e)
{
//do whatever you want
RefreshMyForm();
}
private void RefreshMyForm()
{
//update form with latest Data
}

Related

How to add max value in Progressbar with label(textbox) in C#? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to add a maximum value to the progressbar with the label(textbox).
I am create a simple project for you look image for sample code.
Add a timer for update values.And click timer one time set start with
application true
And add two label.(Sample: label1 is progressbar value / label 2 is progressbar max. value)
And add a button for set progressbar max value.
Code sample:
button1 click event:
progressBar1.Maximum = Int32.Parse(textBox1.value);
timer event: (don't forget set start true with application)
progressBar1.Increment(2); //Loading progressbar
label1.value = Convert.ToString(progressBar1.Value);
label2.value = Convert.ToString(progressBar1.Maximum);
And a image from sample project:
label3 is showing your progressBar max value with timer updating every 1ms.
label5 is showing your progressBar value.

How does timer_tick execute the code block? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Does timer execute the code block each tick even if the code block not completely done ? and if the answer is yes how to make timer tick completes the code block and then start over again.
Yes, it does execute the code each tick even if it's still not done. What you can do is when you execute the code block, stop the timer first, then run it again after the execution of the code block is done.
void Tick_Event(...){
timer.Stop();
// Do something
timer.Start();
}
Hope it helps!
yes you can stop and then start the timer again once you are done with your time taking logic.
void myTick_Tick(object sender, EventArgs e)
{
myTick.Stop();
// your time taking logic here that may take upto some minutes
myTick.Start();
}

Unable to change text of textblock in Windows Phone 8.0 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm trying to set the value of a textblock to what hour it is, I have the following code:
timeHours.Text = DateTime.Now.Hour.ToString();
But the textblock doesn't show what hour it is, it doesn't show anything and stays as the original text, how do I solve this problem?
If you want to show the current hour in a text box, and have it update properly every 60 minutes then you need some sort of background process that changes the value that is displayed in the textbox. You can do this with a simple Timer object and an event.
using System.Timers;
class myclass
{
System.Timers.Timer timer;
public void initialise()
{
timer = new System.Timers.Timer(10000);
timer += new ElapsedEventHandler(_timer_Elapsed);
}
void _timer_Elapsed(object sender, ElapsedEventArgs e)
{
timeHours.Text = DateTime.Now.Hour.ToString();
}
}
This updates the hour every 10 seconds (10000 milliseconds), not very efficient but does the job.

Windows Form C# Button blink On and Off [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have this game in Windows Form that displays 9 buttons on the screen, you have to guess the number the computer thinks, if the number is correct the button should blink/flash on and off. I looked out but i couldn't find any relevant function to help me out. If someone can help me I would really appreciate. Thank you.
You can use the Timer class, which switches the background color of your buttons on the
Elapsed event.
Sample code:
// Create a timer with a ten second interval.
System.Timers.Timer aTimer = new System.Timers.Timer(10000);
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
// Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = 2000;
aTimer.Enabled = true;
The OnTimeEvent function:
void OnTimedEvent(object source, ElapsedEventArgs e)
{
// Change button color
}
Hope it helps :-)

Displaying a message box after a certain period of time [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Hie guys, i have no code at the moment but my problem is like this. i want to display a message box after a certain period of time after an event has occurred lets say after an enquiry has been made and this message box seeks to remind the user to check on the delivery status of the enquiry lets say after 5 minutes. Any ideas or alternatives?
First create a function to show your message, then you can use a timer.tick event to show your message at a given interval
static System.Windows.Threading.DispatcherTimer myTimer = new System.Windows.Threading.DispatcherTimer();
public void DoInquiry()
{
// do your inquiry stuff
////////////////////////
// Set Timer Interval
myTimer.Interval = = new TimeSpan(0,5,0); // 5 Minutes
// Set Timer Event
myTimer.Tick += new EventHandler(TimerEventProcessor);
// Start timer
myTimer.Start();
}
private static void TimerEventProcessor(Object myObject, EventArgs myEventArgs) {
ShowMessage("Please check on the status");
}
protected void ShowMessage(string Message)
{
System.Windows.MessageBox.Show(Message);
}
You would probably want to use a DispatcherTimer. You can use that to check when five minutes have passed then show a MessageBox when appropriate.

Categories