xCoder
February 4th, 2008, 02:52 PM
Hello All,
Using: C# - Visual Studio 2005 (.Net FW 2.0)
I am working on an application that has a function call which will retrieve a list of online computers in local network. That is not the problem it's self.
The function call for this task will get the list and return it in an arraylist object.
When i press the retrieve button, a timer will be enabled that will provide visual feedback to use about progress, since no progress can be calculated here the progress bar goes from 0 to 100 then back to 0 again and so on.
//Retrieve button click
private void toolbtnNew_Click(object sender, EventArgs e)
{
lblStatus.Text = "Listing LAN computers...";
tmrLoading.Enabled = true;
ArrayList list = NetworkBrowser.getListOfComputers();
for (int i = 0; i < list.Count; i++)
lstExplore.Items.Add(list[i]); //LstExplore is a lstView
tmrLoading.Enabled = false;
lblStatus.Text = "Done!";
LoadingProgress.Value = 0;
}
//Timer code
private void tmrLoading_Tick(object sender, EventArgs e)
{
if (LoadingProgress.Value == 100) LoadingProgress.Value = 0;
LoadingProgress.Value+=5;
}
PROBLEM: When Retrieve button is pressed, no visual feedback is given as no update to the progress bar value seem to happen, i am guessing that it's because the getListOfComputers() is a blocking function call, it will stop anything from executing until it's done. But what about timers, aren't they multithreaded?
What would you recommend me to do to solve this tiny problem? I want to know this because it's little things that makes you learn more. So i would like to know what to do when coming to such situation in this project and any other projects.
You are also welcome to give me hints and leave the rest to me.
Best regards and thanks in advance,
xCoder
Using: C# - Visual Studio 2005 (.Net FW 2.0)
I am working on an application that has a function call which will retrieve a list of online computers in local network. That is not the problem it's self.
The function call for this task will get the list and return it in an arraylist object.
When i press the retrieve button, a timer will be enabled that will provide visual feedback to use about progress, since no progress can be calculated here the progress bar goes from 0 to 100 then back to 0 again and so on.
//Retrieve button click
private void toolbtnNew_Click(object sender, EventArgs e)
{
lblStatus.Text = "Listing LAN computers...";
tmrLoading.Enabled = true;
ArrayList list = NetworkBrowser.getListOfComputers();
for (int i = 0; i < list.Count; i++)
lstExplore.Items.Add(list[i]); //LstExplore is a lstView
tmrLoading.Enabled = false;
lblStatus.Text = "Done!";
LoadingProgress.Value = 0;
}
//Timer code
private void tmrLoading_Tick(object sender, EventArgs e)
{
if (LoadingProgress.Value == 100) LoadingProgress.Value = 0;
LoadingProgress.Value+=5;
}
PROBLEM: When Retrieve button is pressed, no visual feedback is given as no update to the progress bar value seem to happen, i am guessing that it's because the getListOfComputers() is a blocking function call, it will stop anything from executing until it's done. But what about timers, aren't they multithreaded?
What would you recommend me to do to solve this tiny problem? I want to know this because it's little things that makes you learn more. So i would like to know what to do when coming to such situation in this project and any other projects.
You are also welcome to give me hints and leave the rest to me.
Best regards and thanks in advance,
xCoder