Results 1 to 19 of 19

Thread: [RESOLVED] Error message

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Resolved [RESOLVED] Error message

    Hi guys,

    I have an application that basically loops through an array of photos and displays them on screen. Now if the photos are more than 24 hours old i try to delete them. But every now and then i keep gettin a message and its the same everytime. I dont know how to stop it from happening so i was hoping somebody could help me out.

    Here is the full error message:

    See the end of this message for details on invoking
    just-in-time (JIT) debugging instead of this dialog box.

    ************** Exception Text **************
    System.IO.IOException: The process cannot access the file 'C:\Documents and Settings\Company\Application Data\Highway 42\Plasma Screen.net\0001451521m.gif' because it is being used by another process.
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.File.Delete(String path)
    at plasma.Form1.cleanUp() in C:\Documents and Settings\Company\My Documents\Visual Studio 2005\Projects\Plasma - 25.10.06\plasma\Form1.vb:line 607
    at plasma.Form1.tmr_Time_Tick(Object sender, EventArgs e) in C:\Documents and Settings\Company\My Documents\Visual Studio 2005\Projects\Plasma - 25.10.06\plasma\Form1.vb:line 571
    at System.Windows.Forms.Timer.OnTick(EventArgs e)
    at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


    ************** Loaded Assemblies **************
    mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
    ----------------------------------------
    plasma
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Documents%20and%20Settings/Company/Desktop/Plasma_26_01_2007/Plasma_26_01_2007/Plasma_26_01_2007/plasma/bin/Release/plasma.exe
    ----------------------------------------
    Microsoft.VisualBasic
    Assembly Version: 8.0.0.0
    Win32 Version: 8.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
    ----------------------------------------
    System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
    ----------------------------------------
    System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    ----------------------------------------
    System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    ----------------------------------------
    System.Runtime.Remoting
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
    ----------------------------------------
    System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
    ----------------------------------------
    System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
    ----------------------------------------

    ************** JIT Debugging **************
    To enable just-in-time (JIT) debugging, the .config file for this
    application or computer (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    enabled.

    For example:

    <configuration>
    <system.windows.forms jitDebugging="true" />
    </configuration>

    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the computer
    rather than be handled by this dialog box.


    Thanks in advance for any help

    Last edited by Kimmy4; Mar 1st, 2007 at 12:03 PM.
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

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

    Re: Error message

    Let me guess, you calling Image.FromFile on that file, correct? If so then read the MSDN help topic for that method and you'll find your answer.
    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: Error message

    No i'm not, when getting the photos to check the last accessed time to delete them i'm using IO.Directory.GetFiles, storing them in an array and then looping through the array to check the last access time.
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  4. #4
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Error message

    I think this thread has some information for you Link
    Please mark you thread resolved using the Thread Tools as shown

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: Error message

    Thanks, but i dont see how that is going to help me as firstly i'm not using Image.FromFile and secondly i'm not using pictureboxes to display my images. I'm using Graphics.DrawImage using GDI+

    ???
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  6. #6
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Error message

    I think you have to display code here?
    Please mark you thread resolved using the Thread Tools as shown

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: Error message

    What code do you need to see....the code to display the image or to delete the file?
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  8. #8
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Error message

    It will be better if we see the coding of displaying the image and deleting the file
    Please mark you thread resolved using the Thread Tools as shown

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: Error message

    This is the code that deletes the files:

    [vbcode]
    Dim twentyFourHours As New TimeSpan(24, 0, 0)
    Dim fileNames As String() = IO.Directory.GetFiles(CACHE_DIRECTORY, "*.jpg")
    Dim fileNames2 As String() = IO.Directory.GetFiles(CACHE_DIRECTORY, "*.gif")
    For r As Integer = 0 To fileNames.GetUpperBound(0) Step 1
    dt = File.GetLastAccessTime(fileNames(r))
    If dt <= Date.Now().Subtract(twentyFourHours) Then
    'Error occurs when trying to delete files at this point
    File.Delete(fileNames(r))
    End If
    Next
    For p As Integer = 0 To fileNames2.GetUpperBound(0) Step 1
    dt2 = File.GetLastAccessTime(fileNames2(p))
    If dt2 <= Date.Now().Subtract(twentyFourHours) Then
    'Error occurs when trying to delete files at this point
    File.Delete(fileNames2(p))
    End If
    Next

    [/vbcode]

    and this is the code that displays the images:

    [vbcode]
    Dim g As Graphics = e.Graphics 'where e is System.Windows.Forms.PaintEventArgs
    g.DrawImage(arrDisplay(f).image1.bmp_Image, New Rectangle(arrDisplay(f)._point.X, arrDisplay(f)._point.Y, iNew_width, iNew_height))
    [/vbcode]
    where arrDisplay is the array that holds all the images and the positions on the screen they should be displayed at and iNew_width and iNew_Height are the height and width the image should be drawn at
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  10. #10
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Error message

    Try placing dispose in this
    Code:
    Dim g As Graphics = e.Graphics 'where e is System.Windows.Forms.PaintEventArgs
    g.DrawImage(arrDisplay(f).image1.bmp_Image, New Rectangle(arrDisplay(f)._point.X, arrDisplay(f)._point.Y, iNew_width, iNew_height))
    g.Dispose()
    Please mark you thread resolved using the Thread Tools as shown

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: Error message

    Ok i'll try that but could you just explain what difference that would make please. And would i need to put that after every g.DrawImage line because i have about 3 or 4 of them???

    Thanks
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

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

    Re: Error message

    If that last block of code is in a Paitn event handler then you certainly shouldn't be disposing it. It was created by the system and it will be disposed by the system

    Presumably this:
    vb Code:
    1. arrDisplay(f).image1.bmp_Image
    refers to a Bitmap object. How are you creating that object? Are you using the Bitmap constructor? If so it locks the file just like Image.FromFile does.
    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
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: Error message

    Yes it refers to a bitmap object. I am getting the image from a downloaded xml file and inserting it into the array using the following code:

    Dim att_large_loc = xml_node.ChildNodes.Item(1).InnerText
    Dim large_file_name As String = Path.GetFileName(att_large_loc)
    arr_xml_images(i).bmp_Image = New Bitmap(CACHE_DIRECTORY & large_file_name)

    CACHE_DIRECTORY is where i am storing the images when they have been downloaded.
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

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

    Re: Error message

    Exactly as I said before. This is from the MSDN help topic for the Bitmap(String) constructor:
    The file remains locked until the Bitmap is disposed.
    If you want to delete the file you have to either dispose all Image objects created from it in that way or using Image.FromFile, or else use some other method of creating the Image that doesn't lock the file.
    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

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: Error message

    Ok thanks.
    What other ways are there that dont lock the files?
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

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

    Re: Error message

    You can open a FileStream, then call Image.FromStream or else use the Bitmap constructor that takes a Stream object. Once you've created the Image you close the stream and the file is unlocked.

    Note that creating Images doesn't just lock files for the sake of it. There is a reason for it and if you don't keep the stream open it can cause issues under some circumstances. That's because there are situations where GDI+ goes back to the stream to read more information and, if it's closed, an exception is thrown. Try it and see. It will most likely be OK but if you get generic GDI+ errors then it's because it's trying to read the stream you closed.
    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

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: Error message

    Ok thanks. I have another little question. I am soon going to be changing my program to introduce XAML to make the display more appealing to look and add a bit more 'snazzy' features to it. Now when i display images do i have to keep the advice you gave me in mind or is there anything else that i should be aware of before changing my code???

    Thanks again
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

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

    Re: Error message

    The only circumstances I'm specifically aware of this issue occurring is if you try to save the Image to another file. There may well be others too though.

    I don't know a thing about XAML.
    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

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: Error message

    Ok thanks for all your help.



    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

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