Click here to Skip to main content
15,921,371 members
Home / Discussions / C#
   

C#

 
AnswerRe: loading machine names from a txt file... Pin
Alan N30-Jul-09 10:22
Alan N30-Jul-09 10:22 
GeneralRe: loading machine names from a txt file... Pin
partialdata31-Jul-09 5:19
partialdata31-Jul-09 5:19 
GeneralRe: loading machine names from a txt file... Pin
Alan N31-Jul-09 5:55
Alan N31-Jul-09 5:55 
GeneralRe: loading machine names from a txt file... Pin
partialdata31-Jul-09 6:53
partialdata31-Jul-09 6:53 
GeneralRe: loading machine names from a txt file... Pin
partialdata31-Jul-09 7:56
partialdata31-Jul-09 7:56 
GeneralRe: loading machine names from a txt file... Pin
Alan N31-Jul-09 9:43
Alan N31-Jul-09 9:43 
GeneralRe: loading machine names from a txt file... Pin
partialdata31-Jul-09 9:58
partialdata31-Jul-09 9:58 
AnswerRe: loading machine names from a txt file... Pin
Alan N31-Jul-09 12:10
Alan N31-Jul-09 12:10 
Hi,
I think you might be better off deferring adding data to the listview until results arrive from the networked computers.

I'm guessing that your program already has code to handle one host name taken from the Host textbox, probably in the Search button click handler, and it should be possible to reuse that code. We refactor the code in the click handler like this:
private void SearchBtn_Click(object sender, EventArgs e) {
  DoTask(HostTextBox.Text);
}


The DoTask method contains all the functionality to query and process the results from ONE networked machine. The advantage of refactoring is that you can now call the DoTask method for each host name in the list, code which could be placed into a menu click handler.
private void OpenFileMenuItem_Click(object sender, EventArgs e) {
  OpenFileDialog fdlg = new OpenFileDialog();
  fdlg.Title = "Load machines to search";
  fdlg.InitialDirectory = @"c:\";
  fdlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
  fdlg.FilterIndex = 2;
  fdlg.RestoreDirectory = true;
  if (fdlg.ShowDialog() == DialogResult.OK) {
    // get machine names from text file
    string[] machineNames = System.IO.File.ReadAllLines(fdlg.FileName);
    foreach (string hostname in machineNames) {
      // query one host
      DoTask(hostname);
      // allow the UI to update
      Application.DoEvents();
    }
  }
}

Now your program can handle a list of hosts, by reading a file, and it can still take a single name from the textbox.

The user interface (UI) can freeze during list processing because the loop prevents any UI updates until iteration has completed. The correct way to keep a UI active is to execute long duration tasks in a secondary thread, but to do that is another level of complexity which I don't think you're ready for just yet. I've inserted a call to Application.DoEvents() into the loop which is the poor man's way of keeping the UI responsive. In simple terms this allows keyboard or mouse input to be read, and the application windows to be redrawn on every iteration. Without it the UI would not update until the loop had ended.


Alan.
QuestionHow to write Newlines in XmlDocument Pin
Jordanwb30-Jul-09 5:38
Jordanwb30-Jul-09 5:38 
AnswerRe: How to write Newlines in XmlDocument Pin
Ian Shlasko30-Jul-09 5:45
Ian Shlasko30-Jul-09 5:45 
GeneralRe: How to write Newlines in XmlDocument Pin
Jordanwb30-Jul-09 5:46
Jordanwb30-Jul-09 5:46 
AnswerRe: How to write Newlines in XmlDocument Pin
PIEBALDconsult30-Jul-09 8:16
mvePIEBALDconsult30-Jul-09 8:16 
QuestionList View item selection Pin
satsumatable30-Jul-09 4:06
satsumatable30-Jul-09 4:06 
Questioncalling button click event Pin
Vivek Vijayan30-Jul-09 3:11
Vivek Vijayan30-Jul-09 3:11 
AnswerRe: calling button click event Pin
DaveyM6930-Jul-09 3:12
professionalDaveyM6930-Jul-09 3:12 
GeneralRe: calling button click event Pin
Vivek Vijayan30-Jul-09 3:18
Vivek Vijayan30-Jul-09 3:18 
GeneralRe: calling button click event Pin
Baeltazor30-Jul-09 17:12
Baeltazor30-Jul-09 17:12 
AnswerRe: calling button click event PinPopular
Mike Ellison30-Jul-09 3:16
Mike Ellison30-Jul-09 3:16 
AnswerRe: calling button click event Pin
PIEBALDconsult30-Jul-09 4:21
mvePIEBALDconsult30-Jul-09 4:21 
AnswerRe: calling button click event Pin
Baeltazor30-Jul-09 17:10
Baeltazor30-Jul-09 17:10 
QuestionFill DataSet with two tables Pin
Rahul DSG30-Jul-09 2:57
Rahul DSG30-Jul-09 2:57 
AnswerRe: Fill DataSet with two tables Pin
stancrm30-Jul-09 3:07
stancrm30-Jul-09 3:07 
GeneralRe: Fill DataSet with two tables Pin
Rahul DSG30-Jul-09 3:16
Rahul DSG30-Jul-09 3:16 
GeneralRe: Fill DataSet with two tables Pin
Robin_Roy30-Jul-09 17:11
Robin_Roy30-Jul-09 17:11 
AnswerRe: Fill DataSet with two tables Pin
Mike Ellison30-Jul-09 3:12
Mike Ellison30-Jul-09 3:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.