I am trying to create a form that queries a database. The form has a "Query" button and I would like the query to run every 30 seconds automatically as well. However, when I try to do it I get an error saying an object reference is needed for QueryBtn since it is non-static.
However, due to the nature of the form I can't change the QueryBtn to static without causing other problems. How can I call on the action of QueryBtn_Click every 30 seconds?
namespace ModalityWorklistSCU
{
public partial class ModalityWorklistSCUExampleForm : Form
{
// Here's the 30 second timer
private static System.Timers.Timer myTimer;
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
myTimer = new System.Timers.Timer();
myTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
myTimer.Interval = 30000;
myTimer.Enabled = true;
Application.Run(new ModalityWorklistSCUExampleForm());
}
// This is the form
public ModalityWorklistSCUExampleForm()
{
InitializeComponent();
}
// This defines what happens when the timer elapses. I am trying to call the click event of another button.
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
QueryBtn.PerformClick();
}
// This is a snipet of the event I want to call every 5 seconds:
private void QueryBtn_Click(object sender, EventArgs e)
{
DCXOBJIterator it = null;
DCXREQ req = null;
DCXOBJ rp = null;
DCXOBJ sps = null;
DCXELM el = null;
DCXOBJIterator spsIt = null;
try
{
// Fill the query object
rp = new DCXOBJ();
sps = new DCXOBJ();
el = new DCXELM();
// Build the Scheduled procedure Step (SPS) item
el.Init((int)DICOM_TAGS_ENUM.ScheduledStationAETitle);
el.Value = StationNameEdit.Text;
sps.insertElement(el);
Thanks