I´m using threads in a c# program, but the process that the threads runs, calls another function that has an infinite loop that locks the program, this is, if I click another option of the Windows Form (ex: close, etc.) it will no longer response.
This loop in necessary and, by now, can not be changed.
Is there a way that I could run this loop like "background" and still use the other options in the program, this is: that the loop does not block the process (I would not like to use threads inside of threads!).
Main Program
|
-------Thread(Function)
|
--------In the function ANOTHER
function is called with
an infinite loop inside
(this loop is NOT part of the
Thread function directly)
EDIT: Adding some example code:
//Here I call the threads
private void userTest_Click(object sender, EventArgs e)
{
for (int i = 0; i < numberOfDevices; i++)
{
try
{
Thread t = new Thread(unused => device(i, sender, e));
t.IsBackground = true;
t.Start();
}
catch (ThreadStateException f)
{
MessageBox.Show("ERROR:" + f); // Display text of exception
}
}
}
The thread function:
//This infinite loop is useless, so it could be deleted. This is not
// the loop I´m talking about
public void device(object i, object s, object f)
{
while (true)
{
if (!killEm)
{
int j = (int)i;
EventArgs g = (EventArgs)f;
BSSDK.BS_SetDeviceID(m_ConnectedDeviceHandle[j],
m_ConnectedDeviceID[j], m_ConnectedDeviceType[j]);
UserManagement userTest = new UserManagement();
userTest.SetDevice(m_ConnectedDeviceHandle[j],
m_ConnectedDeviceID[j], m_ConnectedDeviceType[j]);
userTest.ShowDialog();
}
else
{
userTest.Dispose();
MessageBox.Show("Why don´t u kill it!!?");
break;
}
}
}
In the userTest.ShowDialog() function is the infinite loop I´m talking about
EDIT This is part of the function that is called in userTest.ShowDialog()
private void user_Click(object sender, EventArgs e) {
//THIS IS THE LOOP I´M TALKING!
while (true) {
Keep listening for an user put his finger in the device
...
Do things with that finger template
...
}
}
Thank you.