public partial class Form1 : Form
{
private System.ComponentModel.BackgroundWorker bgw = null;
private Class1 myObject1 = new Class1();
public Form1()
{
InitializeComponent();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (bgw == null)
{
bgw = new BackgroundWorker();
bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
}
if (e.KeyChar == 13 && !bgw.IsBusy)
{
textBox1.Enabled = false;
myObject1.myString = textBox1.Text;
bgw.RunWorkerAsync();
}
}
void bgw_DoWork(object sender, DoWorkEventArgs e)
{
myObject1.queryRecent();
}
void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
label1.Text = myObject1.recentString;
textBox1.Enabled = true;
}
}
|