while images are loading, if we try to close application it is not working.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 11 of 11

Thread: while images are loading, if we try to close application it is not working.

  1. #1
    Join Date
    Apr 2008
    Posts
    22

    while images are loading, if we try to close application it is not working.

    In my project by selecting path loading all png images to application, while loading images if i try to close application its not working, After loading completion it is closing.
    please tell me what is the problem.

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    1. Why would you want to close the application while it is loading the images?

    2. It can't do two things at once. If you start the images loading, then you would need to build in a cancel feature so the loading would stop. Then you could close it.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    if the loading process is under ur code, just put a "DoEvents"
    otherwise, u can use the windows threading API and put the code where it asks the application to load picture in a separate thread. don't forget to interrupt the thread when closing or -in VB- u'll get an expected error.
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  4. #4
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    This isn't VB.NET

    Classic VB applications are single threaded.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  5. #5
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    Quote Originally Posted by Hack
    Classic VB applications are single threaded.
    Yes! they are, but u can use windows API for multithreading it ... well actually built-in VB controls have some kind of multithreading ...
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  6. #6
    Join Date
    Mar 2008
    Location
    Lancashire, UK
    Posts
    156
    Let's see the code, shamsam1

  7. #7
    Join Date
    Apr 2008
    Posts
    22
    The following is the code what I a using

    Private Sub OpenFolder()
    Dim a6() As String
    ReDim a6(Text1.Text + 100000) As String
    Dim t As Double


    On Error GoTo 1:
    Dim i As Long

    If PathFileExists(txtPath) = 0 Then Err.Raise 76
    For i = 0 To ThumbList.Count - 1
    If ThumbList.ItemData(i) > 0 Then Call FreeImage_Unload(ThumbList.ItemData(i))
    Next i
    Call ThumbList.Clear
    t = 0
    For i = 0 To List2.ListCount - 1
    a6(t) = List2.List(i)
    t = t + 1
    Next i

    For i = 0 To t - 1
    Call ThumbList.AddItem(a6(i))
    ThumbList.ItemText(1, ThumbList.Count - 1) = Slsh(File.Path) & a6(i)
    Next i


    If dOnFlyThumbs = 1 Then Exit Sub
    InProc = True
    For i = ThumbList.Count - File.ListCount To ThumbList.Count - 1
    If Not InProc Then Exit For

    Call CreateThumbnail(i) This is the code for loading
    Call DoEventz
    Next i

    lbl_inf = ""
    InProc = False:
    Exit Sub
    1: MsgBox Err.Description, vbExclamation, "OpenFolder"
    End Sub


    In form unload event

    Private Sub Form_Unload(Cancel As Integer)
    Call SaveAllSettings
    Dim i As Long
    For i = 0 To ThumbList.Count - 1

    If ThumbList.ItemData(i) > 0 Then _
    Call FreeImage_Unload(ThumbList.ItemData(i))
    Next i
    For i = 0 To ThumbList1.Count - 1
    If ThumbList1.ItemData(i) > 0 Then _
    Call FreeImage_Unload(ThumbList1.ItemData(i))
    Next i
    Open App.Path & "\savelist.dll" For Output As #1:
    Close #1

    FreeLibrary hLib
    If InProc Then End
    End Sub


    If click form close button while loading images the close button is not getting activated. I dont want to use any extra button for close.

  8. #8
    Join Date
    Mar 2008
    Location
    Lancashire, UK
    Posts
    156
    Simple soloution:
    Code:
    Private Sub Form_Unload(Cancel As Integer)
    
    If InProc Then 'Cancel unloading, and alert the user with a beep
        Cancel = 1
        Beep
        Exit Sub
    End If
    
    Call SaveAllSettings
    Dim i As Long
    For i = 0 To ThumbList.Count - 1
    
    If ThumbList.ItemData(i) > 0 Then _
    Call FreeImage_Unload(ThumbList.ItemData(i))
    Next i
    For i = 0 To ThumbList1.Count - 1
    If ThumbList1.ItemData(i) > 0 Then _
    Call FreeImage_Unload(ThumbList1.ItemData(i))
    Next i
    Open App.Path & "\savelist.dll" For Output As #1:
    Close #1
    
    FreeLibrary hLib
    'If InProc Then End 'Never use End
    End Sub


    Better soloution:
    This will require you to shift some code around a bit...

    Declare a variable at the top, so it's visible to all procedures, e.g.
    Code:
    Private bExiting As Boolean
    Then when Form_Unload is called, JUST set bExiting to true. Move all the code currently in Form_Unload into Form_Terminate for now.
    Then in your loop you need to check if the user has clicked exit:
    Code:
    If dOnFlyThumbs = 1 Then Exit Sub
    InProc = True
    For i = ThumbList.Count - File.ListCount To ThumbList.Count - 1
    If Not InProc Or bExiting Then Exit For 'EDITED HERE
    
    Call CreateThumbnail(i) This is the code for loading
    Call DoEventz
    Next i
    
    lbl_inf = ""
    InProc = False:
    Exit Sub
    1: MsgBox Err.Description, vbExclamation, "OpenFolder"
    End Sub
    In fact, you might get away with leaving the code in Form_Unload.

  9. #9
    Join Date
    Apr 2008
    Posts
    22
    I have changed code from form_unload to form_terminate
    and I have added the boolean variable also.

    Even though my close button is not working if I click. The control is not getting into the event until all images get loaded.

    I debugged the code. But the event starts working after all the images getting loaded.


    The close button is highlighted. But the event code associated is not working.

  10. #10
    Join Date
    Mar 2008
    Location
    Lancashire, UK
    Posts
    156
    Which soloution did you use?

  11. #11
    Join Date
    Apr 2008
    Posts
    22
    I have set the boolean variable and set the follwoing code for loading images,

    If Not InProc Or bExiting Then Exit For

    Then in form_terminate I set bExiting=true
    The close is button highlighting but it is not working to execute the associated code.

Similar Threads

  1. Replies: 0
    Last Post: 11-25-2002, 11:05 PM
  2. loading images dynamically is slow
    By Michael Shutt in forum Web
    Replies: 0
    Last Post: 06-26-2001, 02:25 PM
  3. Painting images in an application
    By Ben CoopeR in forum Java
    Replies: 0
    Last Post: 05-17-2001, 10:58 AM
  4. Java Newbie: Working with GUI Windows
    By Scott in forum Java
    Replies: 0
    Last Post: 11-30-2000, 10:08 AM
  5. Application and Images
    By Al Bowen in forum Java
    Replies: 1
    Last Post: 08-15-2000, 10:58 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