Results 1 to 15 of 15

Thread: [2005] Weird behaviour - form goes blank!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Question [2005] Weird behaviour - form goes blank!

    Hello all.
    I've got an app that is used to analyse the contents of a text file, and displays its progress as it StreamReads the file, before displaying the results.

    What I am noticing is that whilst the app is running, if I switch to another application on my PC (not necessarily open another app, but bring the other app into focus), the window that my VB.NET app occupies is blank when I switch back to it - the window title, the form "outline", etc. is there - but the actual form contents (TextBoxes, Labels, DataGridViews, etc. etc.) is blank.

    If I leave the app to do what it needs to do to complete the analysis of the file, all of a sudden, it jumps back into life and displays the results.

    My question is - why did it disappear in the first place?

    Its not just happening on my PC.
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  2. #2
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: [2005] Weird behaviour - form goes blank!

    The application is too busy to redraw its main screen.
    You need to hive off the busy-ness to an asynchronous process (i.e. another thread)

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2005] Weird behaviour - form goes blank!

    try using
    Code:
    doevents
    statements

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Weird behaviour - form goes blank!

    Quote Originally Posted by .paul.
    try using
    Code:
    doevents
    statements
    No, don't. Use a BackgroundWorker to perform the task in a background thread.

    http://www.vbforums.com/showthread.php?t=471889
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2005] Weird behaviour - form goes blank!

    Thanks. This is better, though still not perfect.
    I've got a progress bar and a label on a StatusStrip. I just happen to be refreshing this status strip to reflect the progress, and this tends to stay visible on the form now. The rest of the form still goes missing, but it does seem to re-appear before the results are shown - whereas it ONLY appeared at results time previously.

    If anybody has any more thoughts or ideas, it'd be appreciated.
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [2005] Weird behaviour - form goes blank!

    as jmc said, a background worker will fix your problem.

    but some strategically placed doevents statements might do it too

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2005] Weird behaviour - form goes blank!

    I've tried putting some Application.DoEvents in at points that I deemed relevant, but this made no real difference.

    The code is structured in the following way. Any comments would be appreciated. Don't know if its worth point out that this was code that I upgraded to VB.NET 2005 from 2003??

    Code:
    Public Class Form1
    
      Private Sub FormLoad
    
         Do some stuff with title bar only
    
      End Sub
    
      Private Sub Button_Click
    
         Locate the text file with file open dialog
    
         Me.BackgroundWorkerReadFile.RunWorkerAsync()
    
      End Sub
    
      Private Sub BackgroundWorkerReadFile_DoWork
    
          Dim worker As System.ComponentModel.BackgroundWorker = DirectCast(sender, System.ComponentModel.BackgroundWorker)
    
          Do While myStreamReader.Peek <> -1
    
                Do some stuff with each line
    
                worker.ReportProgress(intPercent)
    
          Loop
    
      End Sub
    
      Private Sub BackgroundWorkerReadFile_ProgressChanged
    
          Update progress bar
          Refresh StatusStrip
    
      End Sub
    
      Private Sub BackgroundWorkerReadFile_RunWorkerCompleted
    
          Do some stuff, and 
          call the Calculate sub
    
      End Sub
    
      Private Sub Calculate
    
          Do some calculations, and show the results
    
      End Sub
    
    End Class
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Weird behaviour - form goes blank!

    In the ProgressChanged event handler call the form's Refresh method.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2005] Weird behaviour - form goes blank!

    Tried that, but the form then has a horrible 'flicker' - but only noticeably on the DataGrid (not DataGridView). Wonder if I could do something with this as a workaround - hide it until results time??
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Weird behaviour - form goes blank!

    Why are you using a DataGrid in VB 2005?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2005] Weird behaviour - form goes blank!

    Inherited from when it was a VB 2003 app.
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2005] Weird behaviour - form goes blank!

    Then if you don't have this issue with a DataGridView then I suggest you switch. In many cases there shouldn't be much code to change. In others there will be, but it's a superior control in all aspects but one anyway.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2005] Weird behaviour - form goes blank!

    Sorry - I mislead you. There isn't a DataGridView on the form - I was just pointing out that it is a DataGrid, not a DataGridView.

    I've since begun redesigning the app, so the main form is only a file selection and progress indicator form. I'll display the results in a different way.

    Thanks for your help.
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  14. #14
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: [2005] Weird behaviour - form goes blank!

    Quote Originally Posted by penguin5000
    Sorry - I mislead you. There isn't a DataGridView on the form - I was just pointing out that it is a DataGrid, not a DataGridView.

    I've since begun redesigning the app, so the main form is only a file selection and progress indicator form. I'll display the results in a different way.

    Thanks for your help.
    Yes but I belive jmcilhinney ment that you should switch over to using the DataGridView instead, and see if the problem persists.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  15. #15
    New Member
    Join Date
    Oct 2007
    Posts
    1

    Re: [2005] Weird behaviour - form goes blank!

    Hi Penguin,

    I'm so glad you posted this problem. I'm having the exact same problem with my vs 2003 vb project. I too have a separate form to display a progress bar and it was going blank if I switched forms. But Paul's suggestion for Application.doevents solved my problem and I'm wondering if I just got lucky as to the placement of that line in my code.

    Have you tried doevents in the progress bar form's Invalidated event?
    (One other thing: I do a me.refresh for the form after each increment of the bar. This isn't causing any flickering).

    Even if it doesn't work for you, maybe someone else who stumbles upon this thread might have my luck!

    Thanks to all that take the time to help out others!
    Last edited by joch59; Oct 8th, 2007 at 01:17 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width