Click here to Skip to main content
15,907,493 members
Home / Discussions / C#
   

C#

 
GeneralRe: Paste clipboard value to remote application. Pin
sampath Jayasinghe15-Jan-07 16:41
sampath Jayasinghe15-Jan-07 16:41 
QuestionAutocomplete -> BindingSource -> Position change Pin
Glen Harvy13-Jan-07 14:09
Glen Harvy13-Jan-07 14:09 
QuestionSetting a default value for a datagridviewtextbox column Pin
bluewavestrider13-Jan-07 12:07
bluewavestrider13-Jan-07 12:07 
AnswerRe: Setting a default value for a datagridviewtextbox column Pin
Lisa Jorgensen13-Jan-07 15:14
Lisa Jorgensen13-Jan-07 15:14 
GeneralRe: Setting a default value for a datagridviewtextbox column Pin
bluewavestrider14-Jan-07 4:45
bluewavestrider14-Jan-07 4:45 
Questionhow to read status registers of parallel port Pin
George-Lucian13-Jan-07 11:44
George-Lucian13-Jan-07 11:44 
AnswerRe: how to read status registers of parallel port Pin
Phillip M. Hoff13-Jan-07 11:59
Phillip M. Hoff13-Jan-07 11:59 
QuestionA multithreading "best practice" question! Pin
Nader Elshehabi13-Jan-07 10:58
Nader Elshehabi13-Jan-07 10:58 
Hello all.
I've got a common multithreading predicament that might look easy to solve, but I'm looking for best practice. I got some sloppy ideas myself, but I'd like to hear what should be best used in this situation.

1- I'm fetching data from the network server -No problem. Takes about 3-7 secs-.
2- Then I'm populating/refreshing a TreeView from that DataTable which could contain up to 30,000+ records. This is the problem as this takes about 2-3 mins.

I can't allow step two to hold off the user for 2-3 mins until the list is filled. I decided to make another thread to fill up the TreeView while the user still can interact with the rest of the UI. Two questions:
1- Is it normal that a TreeView takes 2-3 mins on a modern Centrino 1.83 laptop with 1.5 GB RAM to add 30,00 nodes? How to speed it up?
2- I got a refresh button that should cancel that active thread, clear the TreeView, then refresh it with node. If I press it twice quickly with my current code, the UI freezes. Any ideas?

If you need to take a look at my sloppy code -Here! Have a nice laugh at it!-, here it is:

private bool StopPopulating;
     private delegate void ClearDel();
     private delegate TreeNode AddDel(string text);

     internal void PopulateList()
     {
         if (!IsPopulating && StopPopulating)
             return;
         IsPopulating = false;
         StopPopulating = true;
         while (Populator != null && Populator.IsAlive)
             Thread.Sleep(1);
         Populator = new Thread(new ThreadStart(PopulateMethod));
         Populator.IsBackground = true;
         Populator.Priority = ThreadPriority.Lowest;
         IsPopulating = true;
         StopPopulating = false;
         Populator.Start();
     }

     private void PopulateMethod()
     {
         lock ("Populating")
         {
             try
             {
                 ClearDel clearing = new ClearDel(Patients.Nodes.Clear);
                 AddDel adding = new AddDel(Patients.Nodes.Add);

                 Patients.BeginInvoke(clearing);
                 CathProxy PatientsProxy = (CathProxy)Activator.GetObject(typeof(CathProxy), CathLab.Url);
                 DataTable mvps = new DataTable();
                 DataTable Pts = PatientsProxy.GetList(out mvps);
                 TreeNode CurrentNode;
                 foreach (DataRow r in Pts.Rows)
                 {
                     if (StopPopulating)
                         return;
                     //CurrentNode = Patients.Nodes.Add('(' + r["Hospital_Number"].ToString() + ") " + r["Patient_Name"].ToString());
                     CurrentNode = (TreeNode)Patients.EndInvoke(Patients.BeginInvoke(adding, new object[] { '(' + r["Hospital_Number"].ToString() + ") " + r["Patient_Name"].ToString() }));

                     foreach (DataRow ro in mvps.Rows)
                     {
                         if (r["Hospital_Number"].ToString() == ro["Hospital_Number"].ToString())
                         {
                             AddDel curadd = new AddDel(CurrentNode.Nodes.Add);
                             Patients.BeginInvoke(curadd, new object[] { "MVP at " + DateTime.Parse(ro["Procedure_Date"].ToString()).ToShortDateString() });
                         }
                     }
                 }
             }
             catch (SystemException ex)
             {
                 MessageBox.Show(ex.Message, "Error populating patients list");
             }
             finally
             {
                 IsPopulating = false;
             }
         }
     }


waiting for bright ideas as I'm out of caffeine!

RegardsRose | [Rose]

AnswerRe: A multithreading "best practice" question! Pin
Phillip M. Hoff13-Jan-07 11:38
Phillip M. Hoff13-Jan-07 11:38 
GeneralRe: A multithreading "best practice" question! Pin
Nader Elshehabi13-Jan-07 12:28
Nader Elshehabi13-Jan-07 12:28 
GeneralRe: A multithreading "best practice" question! Pin
Phillip M. Hoff13-Jan-07 14:25
Phillip M. Hoff13-Jan-07 14:25 
GeneralRe: A multithreading "best practice" question! Pin
Nader Elshehabi14-Jan-07 9:02
Nader Elshehabi14-Jan-07 9:02 
QuestionXNA requirement or Direct x 9 works fine with C#...or OpenGL Pin
Software_Specialist13-Jan-07 10:48
Software_Specialist13-Jan-07 10:48 
AnswerRe: XNA requirement or Direct x 9 works fine with C#...or OpenGL Pin
Nader Elshehabi13-Jan-07 11:12
Nader Elshehabi13-Jan-07 11:12 
GeneralRe: XNA requirement or Direct x 9 works fine with C#...or OpenGL Pin
Software_Specialist13-Jan-07 11:31
Software_Specialist13-Jan-07 11:31 
GeneralRe: XNA requirement or Direct x 9 works fine with C#...or OpenGL Pin
Nader Elshehabi13-Jan-07 12:05
Nader Elshehabi13-Jan-07 12:05 
AnswerRe: XNA requirement or Direct x 9 works fine with C#...or OpenGL Pin
Colin Angus Mackay13-Jan-07 11:39
Colin Angus Mackay13-Jan-07 11:39 
GeneralRe: XNA requirement or Direct x 9 works fine with C#...or OpenGL Pin
Software_Specialist13-Jan-07 12:07
Software_Specialist13-Jan-07 12:07 
QuestionRead Excel file and create another file met some part of first excel file [modified] Pin
teymur_khan13-Jan-07 10:05
teymur_khan13-Jan-07 10:05 
AnswerRe: Read Excel file and create another file met some part of first excel file Pin
Phillip M. Hoff13-Jan-07 11:50
Phillip M. Hoff13-Jan-07 11:50 
GeneralRe: Read Excel file and create another file met some part of first excel file Pin
teymur_khan14-Jan-07 5:14
teymur_khan14-Jan-07 5:14 
Questionhow to manage Device(s) from USB port ? Pin
hdv21213-Jan-07 9:28
hdv21213-Jan-07 9:28 
AnswerRe: how to manage Device(s) from USB port ? Pin
Nader Elshehabi13-Jan-07 10:41
Nader Elshehabi13-Jan-07 10:41 
QuestionAccessing resource on unknown CD-ROM (drive letter). Pin
TrooperIronMan13-Jan-07 9:09
TrooperIronMan13-Jan-07 9:09 
AnswerRe: Accessing resource on unknown CD-ROM (drive letter). Pin
Luc Pattyn13-Jan-07 9:23
sitebuilderLuc Pattyn13-Jan-07 9:23 

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.