A
Andy Straw
Hi, I've been going nuts trying to work out how to do this. I've got an
array list and I've worked out how to get a timer working but I want to
actually use the Timer to do operations on the ArrayList. How do I pass
it a refernce to the arraylist I create?
Any help would be fantastic. TIA
Andy
using System;
using System.Timers;
using System.Collections;
namespace Testing03
{
/// <summary>
/// Summary description for Class1.
/// </summary>
///
class Class1
{
[STAThread]
static void Main(string[] args)
{
ArrayList list1 = new ArrayList();
list1.Add("foo");
list1.Add("bar");
foreach (String s in list1)
{
Console.WriteLine("String...." + s);
}
Timer RefreshTimer = new Timer();
RefreshTimer.Elapsed +=
new ElapsedEventHandler(RefreshTimer_Elapsed);
RefreshTimer.Interval = 10000; //10 secs
RefreshTimer.Enabled = true;
Console.WriteLine("Press Enter to exit....");
Console.Read();
// Keep the timer alive until the end of Main.
GC.KeepAlive(RefreshTimer);
}
private static void
RefreshTimer_Elapsed(object sender, ElapsedEventArgs e)
{
Console.WriteLine("Timer Event");
// really want to do something with list1 here!!
// i.e get rid of the comments around this
// following code block
/*
foreach (String s in list1)
{
Console.WriteLine("String...." + s);
}
*/
}
}
}
array list and I've worked out how to get a timer working but I want to
actually use the Timer to do operations on the ArrayList. How do I pass
it a refernce to the arraylist I create?
Any help would be fantastic. TIA
Andy
using System;
using System.Timers;
using System.Collections;
namespace Testing03
{
/// <summary>
/// Summary description for Class1.
/// </summary>
///
class Class1
{
[STAThread]
static void Main(string[] args)
{
ArrayList list1 = new ArrayList();
list1.Add("foo");
list1.Add("bar");
foreach (String s in list1)
{
Console.WriteLine("String...." + s);
}
Timer RefreshTimer = new Timer();
RefreshTimer.Elapsed +=
new ElapsedEventHandler(RefreshTimer_Elapsed);
RefreshTimer.Interval = 10000; //10 secs
RefreshTimer.Enabled = true;
Console.WriteLine("Press Enter to exit....");
Console.Read();
// Keep the timer alive until the end of Main.
GC.KeepAlive(RefreshTimer);
}
private static void
RefreshTimer_Elapsed(object sender, ElapsedEventArgs e)
{
Console.WriteLine("Timer Event");
// really want to do something with list1 here!!
// i.e get rid of the comments around this
// following code block
/*
foreach (String s in list1)
{
Console.WriteLine("String...." + s);
}
*/
}
}
}