Sleep Command in Vista


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 29

Thread: Sleep Command in Vista

  1. #1
    Join Date
    Mar 2008
    Posts
    61

    Sleep Command in Vista

    Has anyone come across any problems using the Sleep command in their VB6 programs while runing in Vista?

    I have a program that when it goes to sleep it displays the message "The application is not responding. The program may respond again if you wait.". This error causes my program to not work the same way it worked wile runing in XP.

    Thanks in advance
    Bozo

  2. #2
    Join Date
    Jan 2008
    Posts
    73
    Are you referring to the Sleep API?

  3. #3
    Join Date
    Mar 2008
    Posts
    61
    CDRIVE,

    Thanks for you response. Yes I am, I have an app I worte and it has been working fine in XP. When I went to run it on my new Desktop, it does not respond the same way. I have a hidden window that appears and says it is not responding.

    Thanks
    Bozo

  4. #4
    Join Date
    Mar 2008
    Posts
    61
    CDRIVE,

    I have attached a couple of images from of my desktop that may help.

    Bozo
    Attached Images Attached Images

  5. #5
    Join Date
    Jan 2008
    Posts
    73
    The more I read about VB in Vista the more I want to avoid owning it. That said, I did a search that included VB Forums, as I remember seeing a pinned post/FAQ regarding VB in Vista. When I typed Vista into the search box and set it for Titles Only I **** near became ill! I didn't find the FAQ but I did find a plethora of unhappy and frustrated programmers. I'm certain that Hack knows where that FAQ is, so give him a chance to respond.

    In the interim, how long is your Sleep duration and are you aware that the Sleep API halts ALL code execution in any sub/procedure for the duration of the Sleep command? Do Events will have no effect while the Sleep API is active. It is this reason alone that I avoid using it.

  6. #6
    Join Date
    Mar 2008
    Posts
    61
    Thanks again for the reply. I know the sleep command stops processing. That is what I want it to do. My app reads my Outlook Calendar file and displays my appointments that are due for the current day. As the appointments rolle off my calendar, they roll off of my desktop. I don't think it is a duration problem, the screen errors out as soon as it hits the sleep call.

    Thanks for the bad news

    Bozo

  7. #7
    Join Date
    Jan 2008
    Posts
    73
    The reason Iasked for the Sleep duration is because I was considering an alternative to the Sleep API. What is the duration?

  8. #8
    Join Date
    Mar 2008
    Posts
    61
    Well currently it sleeps for 5 minutes, which works great for me. But, the sleep time is a variable which is read from an ini file so other users can adjust to their needs.

  9. #9
    Join Date
    May 2008
    Location
    Chicago, IL
    Posts
    64
    post some code. the sleep api shouldn't cause any issue. if you were using vb.net, you could use threads and events rather than the sleep api.
    David CodeGuru Article: Bound Controls are Evil-VB6

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  10. #10
    Join Date
    Jan 2008
    Posts
    73
    Quote Originally Posted by Bozo
    Well currently it sleeps for 5 minutes, which works great for me. But, the sleep time is a variable which is read from an ini file so other users can adjust to their needs.
    What I was going to suggest is out of the question for a period that long.
    Sorry.

  11. #11
    Join Date
    Mar 2008
    Posts
    61
    Thanks for the efforts CDRIVE.

    dglienna,

    The following is what I am using. It works fine in XP. As far as the .NET, I have not taken the time to delf into it. Some habits are very hard to break.

    Code:
    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    
    Private Sub Main()
    
    Dim objOutlook As New Outlook.Application
    Dim objNS As NameSpace
    Dim Appt As Object
    Dim objInboxItems As Outlook.Items
    Dim apptCount As Integer, boxCounter As Integer
    Dim objAppt As Outlook.AppointmentItem
    Dim Criteria As String, firstPass As Boolean
    Dim screenTop As String, screenLeft As String, alreadyRunning As Boolean
    Dim numberOfLines As Integer, refreshRate As String
    
    alreadyRunning = False
    
    If FSys.FileExists(App.Path & "\" & App.EXEName & ".flg") Then
       Kill (App.Path & "\" & App.EXEName & ".flg")
       alreadyRunning = KillApp("readCalendar.exe")
    Else
       Open App.Path & "\" & App.EXEName & ".flg" For Output As 1
       Print #1, App.EXEName
       Close (1)
    End If
    
    validMachine
    winTools_hwnd = FindWindowByPartialTitle("WinTool")
    
    firstPass = True
    
    checkCalendar:
        
        boxCounter = 0
        
        screenTop = ""
        screenLeft = ""
        
        If FSys.FileExists(App.Path & "\" & App.EXEName & ".ini") Then
          screenTop = ReadINI("ScreenPosition", "Top", App.Path & "\" & App.EXEName & ".ini")
          screenLeft = ReadINI("ScreenPosition", "Left", App.Path & "\" & App.EXEName & ".ini")
          refreshRate = ReadINI("ScreenPosition", "RefreshRate", App.Path & "\" & App.EXEName & ".ini")
        Else
          MsgBox App.Path & "\" & App.EXEName & ".ini file does not exist!" & vbCrLf & "Correct this problem then restart program!"
        End If
       
        If winTools_hwnd Then
           screenLeft = Screen.Width - scheduledItems.Width - 3640
        End If
        
        If firstPass Or scheduledItems.Top <> Val(screenTop) Or scheduledItems.Left <> Val(screenLeft) Then
           scheduledItems.Top = Val(screenTop)
           scheduledItems.Left = Val(screenLeft)
           scheduledItems.Text2(0).Text = "Top - " & scheduledItems.Top
           scheduledItems.Text2(1).Text = "Left - " & scheduledItems.Left
        Else
           scheduledItems.Text2(0).Text = ""
           scheduledItems.Text2(1).Text = ""
        End If
           
           
        
        Criteria = "[Start] >= " & Chr(34) & Format(Now, "mm/dd/yyyy hh:mm AMPM") & Chr(34) & _
               " And [Start] <= " & Chr(34) & Format(Now, "mm/dd/yyyy") & " 11:59 PM" & Chr(34)
             
        Set objNS = objOutlook.GetNamespace("MAPI")
        Set objInboxItems = objNS.GetDefaultFolder(olFolderCalendar).Items
        objInboxItems.Sort ("[Start]")
        objInboxItems.IncludeRecurrences = True
    
        Set Appt = objInboxItems.Restrict(Criteria)
        
        scheduledItems.Text1(boxCounter).Text = ""
        
        If firstPass Then
           Load scheduledItems
           scheduledItems.Show
        End If
     
        apptCount = 0
        
        For Each objAppt In Appt
              
              scheduledItems.Text1(boxCounter).ForeColor = &HFFFFFF
           
              Select Case objAppt.Importance
                 Case 2
                    scheduledItems.Text1(boxCounter).ForeColor = &HFF&
                 Case 1
                    scheduledItems.Text1(boxCounter).ForeColor = &HFFFFFF
              End Select
              
              If objAppt.BusyStatus = 2 Then
                 scheduledItems.Text1(boxCounter).Text = scheduledItems.Text1(boxCounter).Text & objAppt.Start & " - Shown as busy" & vbCrLf
              Else
                 If objAppt.BusyStatus = 1 Then
                    scheduledItems.Text1(boxCounter).Text = scheduledItems.Text1(boxCounter).Text & objAppt.Start & " - Shown as tenative" & vbCrLf
                 Else
                    scheduledItems.Text1(boxCounter).Text = scheduledItems.Text1(boxCounter).Text & objAppt.Start & vbCrLf
                 End If
              End If
              
              scheduledItems.Text1(boxCounter).Text = scheduledItems.Text1(boxCounter).Text & objAppt.Subject & vbCrLf
              scheduledItems.Text1(boxCounter).Text = scheduledItems.Text1(boxCounter).Text & objAppt.Location
                 
              numberOfLines = countLines(scheduledItems.Text1(boxCounter))
              
              Select Case numberOfLines
                 Case 14
                    scheduledItems.Text1(boxCounter).Height = 2525
                 Case 13
                    scheduledItems.Text1(boxCounter).Height = 2700
                 Case 12
                    scheduledItems.Text1(boxCounter).Height = 2490
                 Case 11
                    scheduledItems.Text1(boxCounter).Height = 2285
                 Case 10
                    scheduledItems.Text1(boxCounter).Height = 2075
                 Case 9
                    scheduledItems.Text1(boxCounter).Height = 1870
                 Case 8
                    scheduledItems.Text1(boxCounter).Height = 1660
                 Case 7
                    scheduledItems.Text1(boxCounter).Height = 1450
                 Case 6
                    scheduledItems.Text1(boxCounter).Height = 1245
                 Case 5
                    scheduledItems.Text1(boxCounter).Height = 1035
                 Case 4
                    scheduledItems.Text1(boxCounter).Height = 835
                 Case 3
                    scheduledItems.Text1(boxCounter).Height = 625
                 Case 2
                    scheduledItems.Text1(boxCounter).Height = 410
                 Case 1
                    scheduledItems.Text1(boxCounter).Height = 160
              End Select
              
              scheduledItems.Text1(boxCounter).Visible = True
              
              boxCounter = boxCounter + 1
              Load scheduledItems.Text1(boxCounter)
              If boxCounter <> 0 Then
                 scheduledItems.Text1(boxCounter).Top = scheduledItems.Text1(boxCounter - 1).Top + scheduledItems.Text1(boxCounter - 1).Height
                 scheduledItems.Text1(boxCounter).Left = scheduledItems.Text1(boxCounter - 1).Left
                 scheduledItems.Text1(boxCounter).Visible = False
                 scheduledItems.Text1(boxCounter).Text = "____________________________________________________" & vbCrLf & vbCrLf
              End If
           Set objAppt = objInboxItems.FindNext
           apptCount = apptCount + 1
           
        Next
    
        If apptCount = 0 Then
           scheduledItems.Text1(boxCounter).ForeColor = &HFFFFFF
           scheduledItems.Text1(boxCounter).Text = "No Appointments"
        End If
        
           
        If firstPass Then
           firstPass = False
        End If
       
       Set objAppt = Nothing
       Set Appt = Nothing
       Set objInboxItems = Nothing
       Set objNS = Nothing
       Set objOutlook = Nothing
       
       scheduledItems.Refresh
       
       scheduledItems.Timer1.Interval = 250
       
       Sleep 60000 * Val(refreshRate)
       
       Do While boxCounter > 0
          Unload scheduledItems.Text1(boxCounter)
          boxCounter = boxCounter - 1
       Loop
       
    GoTo checkCalendar
    
    End Sub

  12. #12
    Join Date
    May 2008
    Location
    Chicago, IL
    Posts
    64
    60K * and Integer? that sounds like a killer to me. look how i use the sleep command... Use a small time slice, and count the clicks. You can add a DoEvents if you need as well!

    Code:
    Option Explicit
    ' Add a Timer control to your project.  It will be Timer1
    ' It looks like a stop watch in the IDE.
    Dim OldTime As Date
    Dim newTime As Date
    Dim diff As Long
    
    Private Sub Form_Load()
      OldTime = DateAdd("s", 360, Time) ' Add 360 seconds
      Timer1.Interval = 500
      Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
      newTime = Time
      diff = DateDiff("s", newTime, OldTime)
      Form1.Caption = (diff \ 3600) & ":" & Format((diff \ 60 Mod 60), "00") & ":" & _
            Format((diff - ((diff \ 60) * 60)), "00")
      If diff = 0 Then
        Timer1.Enabled = False
        ' You time is UP!  Do something!
        Beep
      End If
    End Sub
    David CodeGuru Article: Bound Controls are Evil-VB6

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  13. #13
    Join Date
    Mar 2008
    Posts
    61
    dglienna,

    Thanks for checking that out for me. I will try to compile it again tomorrow with your suggestions and let you know the results. I hope that's all it is.

    Thanks
    Bozo

  14. #14
    Join Date
    Mar 2008
    Posts
    61
    dglienna,

    Thanks for the input, but the timer does not stop the app from processing. I need the app to stop for a duration of time. I want to read the Outlook Calendar information every x seconds and display any open appoints for the current day. I compiled the code you provided and the app kept flashing the output on the screen, but it did not display the hidden window. This is why I was using the sleep command in my XP environment.

    I have not used the timer control and was not sure how it functioned.

    Thanks
    Bozo

  15. #15
    Join Date
    Jan 2008
    Posts
    73
    Quote Originally Posted by Bozo
    dglienna,


    I have not used the timer control and was not sure how it functioned.

    Thanks
    Bozo
    Unlike the Sleep command (that can be placed in nearly any procedure) the Timer control works in an opposite fashion. That is, the code that you want to delay execution of is placed in the Timer Sub. The Timer control is not always as convenient because of this. For instance this simple code that would print i% once every 3 seconds until 10 is reached,
    Code:
    For i% = 1 To 10
         Print i%
         Sleep, 3000
         Next
    End Sub
    would be written like this in a Timer control.
    Code:
    Private Sub Timer1_Timer()
        Timer1.Interval = 3000
         i% = i% + 1
         Print i%
             If i% = 10 Then
                 Timer1.Enabled = False
             End If
    End Sub
    As you can see, it's not nearly as convenient as using Sleep, as you have to move all the code that you want delayed into the Timer procedure. Keep in mind that only the code in the Timer procedure is delayed. The rest of your app is not effected.

Similar Threads

  1. sleep
    By ami in forum C++
    Replies: 3
    Last Post: 06-16-2008, 08:55 AM
  2. Replies: 1
    Last Post: 01-10-2008, 08:32 AM
  3. Replies: 0
    Last Post: 09-12-2007, 08:50 AM
  4. Replies: 0
    Last Post: 06-07-2007, 04:07 PM
  5. * Vista Behaviour question *
    By jimbim76 in forum Security
    Replies: 0
    Last Post: 03-28-2007, 10:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center