Im using Visual Studio 2008 and Visual C#
Im developing a Windows application (not Internet-based). I click on a button which calls a function which reads data from some hardware. This can take up to ten minutes. When the data acquisition is complete the data is processed and displayed in charts etc.
The problem is without using threads my application locks up for ten minutes during the acquisition phase. Id like to be able to open some other windows while the data is being acquired.
The attached code shows what Ive tried so far. This basically works correctly as it is shown. When the AcquireData procedure is running I can still use all the other menu options in my application. However when I substitute the Sleep function with the code that actually acquires the data from the hardware then my application locks up and I get the "white-out" effect when I try and click on menus/windows.The data is acquired OK and the results are displayed OK (in the ProcessData function) its just my application is still locked up during the data acquisiion phase.
Does anyone know whats going on. As I say it does what I expect when the Sleep function is in the AcquireData function but nt when I replace this with the code that actually acquires the data.
public partial class Form1 : Form
private delegate void ProcessDataDelegate();
private void button1_Click(object sender, EventArgs e)
Thread trd = new Thread(new ThreadStart(this.AcquireData));
trd.IsBackground = true;
private void AcquireData()
// ...simulated acquiring data...
private void ProcessData()
// ...this is now back on the main UI thread...
this.label1.Text = "Processed data...";