Refreshing a process intensive form and updating after lost focus 
Author Message
 Refreshing a process intensive form and updating after lost focus

Hi All,

I will try to explain what I mean,

I have a form that has code in it that is pretty intensive.

e.g.

            FileOpen(hFile, sPath, OpenMode.Binary, OpenAccess.Read,
OpenShare.LockReadWrite)
            FileGet(hFile, sStream)
            StatusBar.Text = "Processing user list : "
            StatusBar.Refresh()
            OkCancelPanel.Visible = False
            IconProgress.Visible = True
            Progress.Maximum = Len(sStream)
            ' StatusBar.Width = Me.Width - 60
            Progress.Step = 1
            Progress.Visible = True
            Pic1.Visible = True
            Pic1.Refresh()
            dtTime = Now
            While Len(sStream) > 0
                Me.Refresh()
                ShowIcons()
                dLen = sStream.IndexOf(Chr(13) & Chr(10))
                If dLen <= 0 Then
                    dLen = 0
                End If
                sLine = sStream.Substring(0, dLen)
                sStream = sStream.Substring(dLen + 2)
                Progress.Value = Progress.Maximum - Len(sStream)
                alIni.Add(sLine)
            End While

The problem is that when you click on to another window and then click back
the form does not repaint the contents.
In the task manager of Windows XP the program shows that it is not
responding although I know it is processing.
How do I get this code to relinquish control to the OS momentarily so that
other timer events and the repaint of the form can get a bit of the
processing power.

e.g.

            FileOpen(hFile, sPath, OpenMode.Binary, OpenAccess.Read,
OpenShare.LockReadWrite)
            FileGet(hFile, sStream)
            StatusBar.Text = "Processing user list : "
            StatusBar.Refresh()
            OkCancelPanel.Visible = False
            IconProgress.Visible = True
            Progress.Maximum = Len(sStream)
            ' StatusBar.Width = Me.Width - 60
            Progress.Step = 1
            Progress.Visible = True
            Pic1.Visible = True
            Pic1.Refresh()
            dtTime = Now
            While Len(sStream) > 0

                APPLICATION.IDLE()

                ShowIcons()
                dLen = sStream.IndexOf(Chr(13) & Chr(10))
                If dLen <= 0 Then
                    dLen = 0
                End If
                sLine = sStream.Substring(0, dLen)
                sStream = sStream.Substring(dLen + 2)
                Progress.Value = Progress.Maximum - Len(sStream)
                alIni.Add(sLine)
            End While

Thank You
Mark Hollander



Sat, 07 May 2005 19:40:54 GMT  
 Refreshing a process intensive form and updating after lost focus
On occassion, you should execute the following:

  System.Windows.Forms.Application.DoEvents()

This allows the system to process any messages in the
queue.  Maybe you can put in a counter, and every 25 or 50
iterations execute the above statement.  You may not want
to execute this every time through the loop.  What your
iteration count should be would depend on how fast your
loop processes and maybe how often you switch back to the
process.

-Lee

Quote:
>-----Original Message-----
>Hi All,

>I will try to explain what I mean,

>I have a form that has code in it that is pretty
intensive.

>e.g.

>            FileOpen(hFile, sPath, OpenMode.Binary,
OpenAccess.Read,
>OpenShare.LockReadWrite)
>            FileGet(hFile, sStream)
>            StatusBar.Text = "Processing user list : "
>            StatusBar.Refresh()
>            OkCancelPanel.Visible = False
>            IconProgress.Visible = True
>            Progress.Maximum = Len(sStream)
>            ' StatusBar.Width = Me.Width - 60
>            Progress.Step = 1
>            Progress.Visible = True
>            Pic1.Visible = True
>            Pic1.Refresh()
>            dtTime = Now
>            While Len(sStream) > 0
>                Me.Refresh()
>                ShowIcons()
>                dLen = sStream.IndexOf(Chr(13) & Chr(10))
>                If dLen <= 0 Then
>                    dLen = 0
>                End If
>                sLine = sStream.Substring(0, dLen)
>                sStream = sStream.Substring(dLen + 2)
>                Progress.Value = Progress.Maximum - Len
(sStream)
>                alIni.Add(sLine)
>            End While

>The problem is that when you click on to another window
and then click back
>the form does not repaint the contents.
>In the task manager of Windows XP the program shows that
it is not
>responding although I know it is processing.
>How do I get this code to relinquish control to the OS
momentarily so that
>other timer events and the repaint of the form can get a
bit of the
>processing power.

>e.g.

>            FileOpen(hFile, sPath, OpenMode.Binary,
OpenAccess.Read,
>OpenShare.LockReadWrite)
>            FileGet(hFile, sStream)
>            StatusBar.Text = "Processing user list : "
>            StatusBar.Refresh()
>            OkCancelPanel.Visible = False
>            IconProgress.Visible = True
>            Progress.Maximum = Len(sStream)
>            ' StatusBar.Width = Me.Width - 60
>            Progress.Step = 1
>            Progress.Visible = True
>            Pic1.Visible = True
>            Pic1.Refresh()
>            dtTime = Now
>            While Len(sStream) > 0

>                APPLICATION.IDLE()

>                ShowIcons()
>                dLen = sStream.IndexOf(Chr(13) & Chr(10))
>                If dLen <= 0 Then
>                    dLen = 0
>                End If
>                sLine = sStream.Substring(0, dLen)
>                sStream = sStream.Substring(dLen + 2)
>                Progress.Value = Progress.Maximum - Len
(sStream)
>                alIni.Add(sLine)
>            End While

>Thank You
>Mark Hollander

>.



Sat, 07 May 2005 20:43:45 GMT  
 Refreshing a process intensive form and updating after lost focus
Thank You

Quote:
> On occassion, you should execute the following:

>   System.Windows.Forms.Application.DoEvents()

> This allows the system to process any messages in the
> queue.  Maybe you can put in a counter, and every 25 or 50
> iterations execute the above statement.  You may not want
> to execute this every time through the loop.  What your
> iteration count should be would depend on how fast your
> loop processes and maybe how often you switch back to the
> process.

> -Lee

> >-----Original Message-----
> >Hi All,

> >I will try to explain what I mean,

> >I have a form that has code in it that is pretty
> intensive.

> >e.g.

> >            FileOpen(hFile, sPath, OpenMode.Binary,
> OpenAccess.Read,
> >OpenShare.LockReadWrite)
> >            FileGet(hFile, sStream)
> >            StatusBar.Text = "Processing user list : "
> >            StatusBar.Refresh()
> >            OkCancelPanel.Visible = False
> >            IconProgress.Visible = True
> >            Progress.Maximum = Len(sStream)
> >            ' StatusBar.Width = Me.Width - 60
> >            Progress.Step = 1
> >            Progress.Visible = True
> >            Pic1.Visible = True
> >            Pic1.Refresh()
> >            dtTime = Now
> >            While Len(sStream) > 0
> >                Me.Refresh()
> >                ShowIcons()
> >                dLen = sStream.IndexOf(Chr(13) & Chr(10))
> >                If dLen <= 0 Then
> >                    dLen = 0
> >                End If
> >                sLine = sStream.Substring(0, dLen)
> >                sStream = sStream.Substring(dLen + 2)
> >                Progress.Value = Progress.Maximum - Len
> (sStream)
> >                alIni.Add(sLine)
> >            End While

> >The problem is that when you click on to another window
> and then click back
> >the form does not repaint the contents.
> >In the task manager of Windows XP the program shows that
> it is not
> >responding although I know it is processing.
> >How do I get this code to relinquish control to the OS
> momentarily so that
> >other timer events and the repaint of the form can get a
> bit of the
> >processing power.

> >e.g.

> >            FileOpen(hFile, sPath, OpenMode.Binary,
> OpenAccess.Read,
> >OpenShare.LockReadWrite)
> >            FileGet(hFile, sStream)
> >            StatusBar.Text = "Processing user list : "
> >            StatusBar.Refresh()
> >            OkCancelPanel.Visible = False
> >            IconProgress.Visible = True
> >            Progress.Maximum = Len(sStream)
> >            ' StatusBar.Width = Me.Width - 60
> >            Progress.Step = 1
> >            Progress.Visible = True
> >            Pic1.Visible = True
> >            Pic1.Refresh()
> >            dtTime = Now
> >            While Len(sStream) > 0

> >                APPLICATION.IDLE()

> >                ShowIcons()
> >                dLen = sStream.IndexOf(Chr(13) & Chr(10))
> >                If dLen <= 0 Then
> >                    dLen = 0
> >                End If
> >                sLine = sStream.Substring(0, dLen)
> >                sStream = sStream.Substring(dLen + 2)
> >                Progress.Value = Progress.Maximum - Len
> (sStream)
> >                alIni.Add(sLine)
> >            End While

> >Thank You
> >Mark Hollander

> >.



Sat, 07 May 2005 22:07:25 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Why does my Form lose focus?

2. Form locks and dies when app focus is lost

3. Catching form losing focus to another app

4. Catching form losing focus to another app

5. Form close event occurs before lost focus event

6. Creating Forms that wont lose focus

7. Non MDI child forms cause MDI application to lose focus

8. Lost focus on forms VB 5 EE

9. MDI child forms and control lost-focus events

10. How can i make my form to lose the focus

11. Trying again: How to make form lose focus?

12. Why main form lost focus?

 

 
Powered by phpBB® Forum Software