ورود

View Full Version : سوال: فراخوانی Timer در Global.asax



hamid1988
شنبه 21 دی 1392, 19:25 عصر
سلام دوستان
چطور میتونم Timer رو در Global.asax فراخوانی کنم تا مثلاَ هر یک دقیقه یه کاری رو برام انجام بده؟

saeedsa
پنج شنبه 08 خرداد 1393, 09:46 صبح
salam dost aziz
ravesh manteghi ine ke ye script benevisi be server ya host bedi va har zamani ke mikhai on scripto seda kone
dar ghyre in sorat global.asax
inam raveshesh



<%@ Application Language="C#" %>
<%@ Import Namespace="System.Threading" %>


<script RunAt="server">
.....
....


void Application_Start(object sender, EventArgs e)
{

ThreadStart tstread = new ThreadStart(TaskLoop);
Thread Mytask = new Thread(tstread);
Mytask.Start();




}
public void TaskLoop() {
// In this example, task will repeat in infinite loop
// You can additional parameter if you want to have an option
// to stop the task from some page
while (true)
{
// Execute scheduled task
ScheduledTask();


//// Wait for certain time interval
System.Threading.Thread.Sleep(TimeSpan.FromSeconds (120));
}
}

public void ScheduledTask() {
PublicFunc sa90 = new PublicFunc();
sa90.recivesms();
}




movafagh bashid