Click here to Skip to main content
15,880,608 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
I want to call a specific function on my C#-WPF MVVM application at a specific time.I'm using System.Timers in My application.But later I realized that its impossible to achieve my goal using that.

Is anybody can suggest me a good solution for this.?
Thanks in advance...!!!
Posted
Comments
Sergey Alexandrovich Kryukov 24-Jan-12 2:14am    
First, why would you do such thing? If you are trying to do anything weird, you should always explain why. Who would like to waste time on "how" it "what" is maybe wrong?

Second, "it's impossible" is simply not true. Who told you so? This is possible and even easy. So, please see what's your problem here?

--SA
CGN007 24-Jan-12 3:45am    
Sorry...
Here is my problem details
I want to send mails by selecting any of the two options,
1.Each -- day of month
2.Each -- day of week
The user inputs which day and the start time...
Thanks for your time...!!!

1 solution

Why did you realize that System.Timers was impossible
But it works well for me!

C#
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
        Dispatcher.Invoke((Action)delegate()
	{

		if(Your Conditions)
			YourMethod();

	});
}
 
Share this answer
 
Comments
CGN007 24-Jan-12 3:47am    
I want to send mails by selecting any of the two options, 1.Each -- day of month 2.Each -- day of week The user inputs which day and the start time... Its Problem...

Can it possible using the code...!!!
Shahin Khorshidnia 24-Jan-12 4:07am    
Yes, make a method check all user's condition. for example CheckUsers().
You can also have a precondition.
for example:

if (DateTime.Now.Hour != 12)
return;

If (CheckUsers())
YourMethod();


Then YourMethod() will be done at 12 O'clock everyday.
you can complite the code for performing the method only one time daily.
CGN007 24-Jan-12 4:18am    
I think I need to set the timer interval also...
How can I identify the interval value?
Please correct me ,If I'm wrong...
Shahin Khorshidnia 24-Jan-12 4:26am    
private void Window_Loaded(object sender, RoutedEventArgs e)
{
timer = new System.Timers.Timer();
timer.Interval = 1800000;
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
timer.Start();
}
CGN007 24-Jan-12 4:43am    
Thanks...
I Think I can Identify the exact interval value like this
DateTime StartTime = DateTime.ParseExact("22:22:22", "HH:mm:ss", new DateTimeFormatInfo());
TimeSpan ts1 = StartTime.Subtract(DateTime.Now.ToLocalTime());
double Interval = ts1.TotalMilliseconds;
Shall I proceed like this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900