C#, multi-threading DataGridView scrollbar issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RodneyAnonymous
    New Member
    • Oct 2007
    • 15

    C#, multi-threading DataGridView scrollbar issue

    I'm trying to add multi-thread capabilities to a program I am writing so the users aren't locked into loading a potentially large log file without being able to use the program for anything else. Everything is running smoothly, except that when the new thread finishes, the scrollbar for my DataGridView is horrendously broken. It appears as fragments of other parts of the interface, or not at all, and cannot be clicked on to scroll.

    Here's a snippet of the code I'm using to open the new thread up:

    Thread workThread = new Thread(LoadLog) ;
    workThread.Star t(openFileDialo g1.FileName);

    The code for LoadLog is extremely large, but what it is doing is parsing log lines into a more readable format, and using DataGridView.Ro ws.Add(blah, blah, blah) to update the DGV.

    I've tried calling Refresh and turning ScrollBars on/off from within the thread, as well as making a delegate for the DGV's Refresh function and calling it at the end. The latter completely locked up my program whenever the number of lines called for the DGV to have a scroll bar.

    Does anyone have any idea what the problem is and what I can do to fix it?
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    The biggest issue I've had with threading data into the UI is refreshing the form. I would suggest using a delegate to populate each row of your gridview rather than to refresh the gridview. Without seeing any of your code, I can't guarantee it though, just a hunch.

    Comment

    • RodneyAnonymous
      New Member
      • Oct 2007
      • 15

      #3
      Wouldn't that entirely defeat the purpose of using multi-threading to begin with, though? Using a delegate to add the rows will just put the load back on the main thread, which will lock up the rest of the program.

      Comment

      Working...