Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

vb.net background worker stops processing code on large file copy

Posted on 2010-09-14
2
882 Views
Last Modified: 2012-05-10
Basically small files (under 500MB) all process perfectly, but large files such as 3-4GB movie files hang up the code so it never finishes...

basically it doesn't look like the BGW does anything after the bgw.reportprogress(0, filename) code. It should email and it should delete the original file, but it stops.

Does a BGW have a timeout or anything like that?

Can someone please take a look and tell me why it would only stop working on large files? It will mostly process one large file but stops directly after the bgw progress changed command.
Private Sub bgw_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgw.DoWork
        Dim FileName As String
        Dim HasMoreItems As Boolean
        Dim Mbpslower As String
        Mbpslower = "15Mbps"
        While True
            Files.MRE.Reset()
            HasMoreItems = False
            Do
                FileName = Nothing
                SyncLock Files.SharedObject
                    If Files.ToBeProcessed.Count > 0 Then
                        FileName = Files.ToBeProcessed.Peek
                    End If
                End SyncLock
                If Not IsNothing(FileName) Then
                    While IsFileInUse(FileName)
                        Debug.Print(DateTime.Now.ToString() & " : File in use!  Waiting 5 seconds...")
                        System.Threading.Thread.Sleep(5000) ' wait 5 seconds to try again
                    End While

                    Dim hiDef As String = "HD"
                    Dim FVOD1 As String = "FVOD"
                    Dim Fifteen As String = "15Mbps"

                    If FileName.ToLower.Contains(hiDef.ToLower) Or FileName.ToLower.Contains(FVOD1.ToLower) Or FileName.ToLower.Contains(Fifteen.ToLower) Or FileName.ToLower.Contains("ipvod".ToLower) Then

                        Good(FileName)

                    Else
                        Bad(FileName)

                    End If
                End If

                SyncLock Files.SharedObject
                    HasMoreItems = (Files.ToBeProcessed.Count > 0)
                End SyncLock
            Loop While HasMoreItems
            Files.MRE.WaitOne()
        End While
        'End If

    End Sub

    Private Sub Good(ByVal FileName As String)

        Dim Mbpslower As String
        Mbpslower = "15Mbps"

        Try

            If FileName.ToLower.Contains(Mbpslower.ToLower) Then
                bgw.ReportProgress(0, FileName)
                System.IO.File.Copy("C:\video\" & FileName, "X:\encoded2\mcvod\transcode_needed\" & FileName, True)

            Else

                System.IO.File.Copy("C:\video\" & FileName, "X:\CPS\" & FileName, True)

                System.IO.File.Copy("C:\video\" & FileName, "X:\Encoded2\" & FileName, True)

            End If

            SyncLock Files.SharedObject
                Files.ToBeProcessed.Dequeue()
            End SyncLock
            bgw.ReportProgress(0, FileName)

        Catch ex As Exception
            System.Threading.Thread.Sleep(5000) ' wait 5 seconds before trying again
        End Try

        If FileName.ToLower.Contains(Mbpslower.ToLower) Then
            GoTo finish
        Else
            GoTo email
        End If






email:
        'Email code removed, but this code works perfectly
        Dim objWriter As New System.IO.StreamWriter("C:\UploadLog.txt", True)
        objWriter.WriteLine(FileName)
        objWriter.Close()
        GoTo finish
finish:
        System.IO.File.Delete("C:\Video\" & FileName)
    End Sub

Open in new window

Private Sub bgw_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgw.DoWork
        Dim FileName As String
        Dim HasMoreItems As Boolean
        Dim Mbpslower As String
        Mbpslower = "15Mbps"
        While True
            Files.MRE.Reset()
            HasMoreItems = False
            Do
                FileName = Nothing
                SyncLock Files.SharedObject
                    If Files.ToBeProcessed.Count > 0 Then
                        FileName = Files.ToBeProcessed.Peek
                    End If
                End SyncLock
                If Not IsNothing(FileName) Then
                    While IsFileInUse(FileName)
                        Debug.Print(DateTime.Now.ToString() & " : File in use!  Waiting 5 seconds...")
                        System.Threading.Thread.Sleep(5000) ' wait 5 seconds to try again
                    End While

                    Dim hiDef As String = "HD"
                    Dim FVOD1 As String = "FVOD"
                    Dim Fifteen As String = "15Mbps"

                    If FileName.ToLower.Contains(hiDef.ToLower) Or FileName.ToLower.Contains(FVOD1.ToLower) Or FileName.ToLower.Contains(Fifteen.ToLower) Or FileName.ToLower.Contains("ipvod".ToLower) Then

                        Good(FileName)

                    Else
                        Bad(FileName)

                    End If
                End If

                SyncLock Files.SharedObject
                    HasMoreItems = (Files.ToBeProcessed.Count > 0)
                End SyncLock
            Loop While HasMoreItems
            Files.MRE.WaitOne()
        End While
        'End If

    End Sub

    Private Sub Good(ByVal FileName As String)

        Dim Mbpslower As String
        Mbpslower = "15Mbps"

        Try

            If FileName.ToLower.Contains(Mbpslower.ToLower) Then
                bgw.ReportProgress(0, FileName)
                System.IO.File.Copy("C:\video\" & FileName, "X:\encoded2\mcvod\transcode_needed\" & FileName, True)

            Else

                System.IO.File.Copy("C:\video\" & FileName, "X:\CPS\" & FileName, True)

                System.IO.File.Copy("C:\video\" & FileName, "X:\Encoded2\" & FileName, True)

            End If

            SyncLock Files.SharedObject
                Files.ToBeProcessed.Dequeue()
            End SyncLock
            bgw.ReportProgress(0, FileName)

        Catch ex As Exception
            System.Threading.Thread.Sleep(5000) ' wait 5 seconds before trying again
        End Try

        If FileName.ToLower.Contains(Mbpslower.ToLower) Then
            GoTo finish
        Else
            GoTo email
        End If






email:
        'Email code removed, but this code works perfectly
        Dim objWriter As New System.IO.StreamWriter("C:\UploadLog.txt", True)
        objWriter.WriteLine(FileName)
        objWriter.Close()
        GoTo finish
finish:
        System.IO.File.Delete("C:\Video\" & FileName)
    End Sub

Open in new window

0
Comment
Question by:MaxDes101
2 Comments
 
LVL 29

Accepted Solution

by:
nffvrxqgrcfqvvc earned 500 total points
ID: 33676035
lines 16 to 20.. Do you keep running this loop if a file is in use? What if the file doesn't release then it just sits there?
0
 

Author Closing Comment

by:MaxDes101
ID: 33676675
file wasn't being release. You are right. thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question