Hi Mark,
For your scenario, what you want to do is like a background task scheduler
or timer which constantly do jobs in background and other pages can query
data from its status storage. I think you can achieve this through the
following means:
** define a public class which expose some static property and methods so
that other page can access it during the ASP.NET application's entire
lifecycle.
** This class will create a background thread(you can also create a timer
instance for this) and do some work in the thread procedure function.
Here is a very simple demo class:
======================
public class GlobalDataStore
{
public static string CurrentMessage;
private static Thread _thread = null;
private static bool _run = false;
public GlobalDataStore()
{
}
public static void StartProcessor()
{
if (_thread != null)
{
return;
}
_thread = new Thread(new ThreadStart(Thread_Proc));
_run = true;
_thread.Start();
}
public static void StopProcessor()
{
if (_thread != null)
{
_run = false;
_thread.Join();
}
}
private static void Thread_Proc()
{
while (_run)
{
CurrentMessage = "Ticks: " + DateTime.Now.Ticks;
Thread.Sleep(2000);
}
}
}
=======================
thus, you can call the StartProcessor method in Global.asax object
"Application_Start" event or in any other place you want to start the
background task. Then, you can also query the status or result producted by
the background thread through some exposed public static properties of this
class(like the "CurrentMessage" here).
Hope this helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.