|
-
Sep 18th, 2007, 10:52 AM
#1
Thread Starter
Addicted Member
[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.
-
Sep 18th, 2007, 10:57 AM
#2
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)
-
Sep 18th, 2007, 10:21 PM
#3
Re: [2005] Weird behaviour - form goes blank!
-
Sep 18th, 2007, 10:32 PM
#4
Re: [2005] Weird behaviour - form goes blank!
 Originally Posted by .paul.
No, don't. Use a BackgroundWorker to perform the task in a background thread.
http://www.vbforums.com/showthread.php?t=471889
-
Sep 19th, 2007, 10:26 AM
#5
Thread Starter
Addicted Member
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.
-
Sep 19th, 2007, 10:31 AM
#6
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
-
Sep 20th, 2007, 04:52 AM
#7
Thread Starter
Addicted Member
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
-
Sep 20th, 2007, 04:55 AM
#8
Re: [2005] Weird behaviour - form goes blank!
In the ProgressChanged event handler call the form's Refresh method.
-
Sep 20th, 2007, 05:36 AM
#9
Thread Starter
Addicted Member
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??
-
Sep 20th, 2007, 05:39 AM
#10
Re: [2005] Weird behaviour - form goes blank!
Why are you using a DataGrid in VB 2005?
-
Sep 20th, 2007, 05:46 AM
#11
Thread Starter
Addicted Member
Re: [2005] Weird behaviour - form goes blank!
Inherited from when it was a VB 2003 app.
-
Sep 20th, 2007, 09:06 AM
#12
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.
-
Sep 21st, 2007, 04:23 AM
#13
Thread Starter
Addicted Member
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.
-
Sep 21st, 2007, 06:28 AM
#14
Re: [2005] Weird behaviour - form goes blank!
 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.
-
Oct 6th, 2007, 01:55 PM
#15
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|