Cross-thread operation not valid: Control 'Form1' accessed from a thread other than the thread it was created on.
[code=C#]
using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows. Forms;
using System.Timers;
namespace WindowsFormsApp lication2
{
public partial class Form1 : Form
{
private static System.Timers.T imer aTimer;
public Form1()
{
InitializeCompo nent();
aTimer = new System.Timers.T imer();
aTimer.Elapsed += new ElapsedEventHan dler(found_card );
// Set the Interval to 2 seconds.
aTimer.Interval = 1000;
aTimer.Enabled = true;
}
private void found_card(obje ct sender, EventArgs e)
{
aTimer.Enabled = false;
// use smart card system to find the card. if found the card, it will open form2 and close form1
Form form2 = new Form2();
this.Hide(); // <--- error, please help me to make a solution
form2.ShowDialo g();
this.Close();
}
}
}
[/code]
[code=C#]
using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows. Forms;
using System.Timers;
namespace WindowsFormsApp lication2
{
public partial class Form1 : Form
{
private static System.Timers.T imer aTimer;
public Form1()
{
InitializeCompo nent();
aTimer = new System.Timers.T imer();
aTimer.Elapsed += new ElapsedEventHan dler(found_card );
// Set the Interval to 2 seconds.
aTimer.Interval = 1000;
aTimer.Enabled = true;
}
private void found_card(obje ct sender, EventArgs e)
{
aTimer.Enabled = false;
// use smart card system to find the card. if found the card, it will open form2 and close form1
Form form2 = new Form2();
this.Hide(); // <--- error, please help me to make a solution
form2.ShowDialo g();
this.Close();
}
}
}
[/code]
Comment