Click here to Skip to main content
15,889,876 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Questionhow to insert image in the database Pin
Member 1063213016-Dec-14 3:49
Member 1063213016-Dec-14 3:49 
GeneralRe: how to insert image in the database Pin
PIEBALDconsult16-Dec-14 4:12
mvePIEBALDconsult16-Dec-14 4:12 
AnswerRe: how to insert image in the database Pin
Chris Quinn16-Dec-14 21:49
Chris Quinn16-Dec-14 21:49 
GeneralRe: how to insert image in the database Pin
Eddy Vluggen17-Dec-14 7:23
professionalEddy Vluggen17-Dec-14 7:23 
AnswerRe: how to insert image in the database Pin
Otekpo Emmanuel17-Dec-14 6:38
Otekpo Emmanuel17-Dec-14 6:38 
QuestionPls HELP me How to print data from datagridview bind on access database Pin
Member 1131194915-Dec-14 2:06
Member 1131194915-Dec-14 2:06 
AnswerRe: Pls HELP me How to print data from datagridview bind on access database Pin
Eddy Vluggen15-Dec-14 3:04
professionalEddy Vluggen15-Dec-14 3:04 
QuestionProper us of await Pin
jkirkerx14-Dec-14 13:50
professionaljkirkerx14-Dec-14 13:50 
Well my previous post, the await part didn't work, and it operated synchronously.

The main code was suppose to pause and wait for the download to complete and the program to install before moving forward, but just ran to the end.

The previous code I wrote had awaits everywhere in the main code. I really just wanted to call a class that would do the whole thing for me in 1 shot, while the main code waits for the class to finish.

I'm not really sure what this is called in .NET to look up info; perhaps a delegate. And how to adjust my code, and get rid of the await if I have to.

Calling the class, I use to have the await here as well, but then the await kept going up the chain, until finally everything was an await task in the main program - hard to explain.

I didn't think it would be this hard, and I'm having trouble sifting through all the information on the net, and choosing the proper direction / method to take.
Dim localDB_Url_X64 As String = "http://care.dlservice.microsoft.com/dl/download/E/A/E/EAE6F7FC-767A-4038-A954-49B8B05D04EB/LocalDB%2064BIT/SqlLocalDB.msi"
Dim localDB_Url_X86 As String = "http://care.dlservice.microsoft.com/dl/download/E/A/E/EAE6F7FC-767A-4038-A954-49B8B05D04EB/LocalDB%2032BIT/SqlLocalDB.msi"
Dim desktop_Save As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\SqlLocalDB.msi"

Dim dCB As New download_callback
dCB.httpWebRequest_With_Progress(
  New Uri(localDB_Url_X64).ToString, 
  desktop_Save, 
  lbl_localDB_Progress, 
  pbLocalDB
)

My Class - I really just wanted to call this class, and wait for it to finish, but be able to update my progress bar and label. It's a pretty long task, perhaps 10 minutes or so.
The code in the class actually works correctly, and does what I want, just doesn't pause and wait.
Public Class download_callback

    Public Async Function httpWebRequest_With_Progress( _
        ByVal url As String,
        ByVal s As String,
        ByVal pLabel As Label,
        ByVal pBar As ProgressBar) As Task(Of Integer)

        Dim desktop_Save As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\SqlLocalDB.msi"
        Dim webClient As Net.HttpWebRequest = DirectCast(Net.HttpWebRequest.Create(url), Net.HttpWebRequest)
        webClient.AllowAutoRedirect = True

        Dim resp = Await (New TaskFactory(Of Net.WebResponse)).StartNew(AddressOf webClient.GetResponse)
        pBar.Value = 0
        pBar.Maximum = CInt(resp.ContentLength)
        Dim rqs = resp.GetResponseStream

        Dim bufferSize As Integer = 1 << 16
        Dim buffer(bufferSize) As Byte
        Dim bytesRecieved As Integer = 0
        Dim bytesTotal As Integer = 0

        Dim fs As New FileStream(desktop_Save, FileMode.Create)

        Do
            bytesRecieved = Await (New TaskFactory(Of Integer)).FromAsync(AddressOf rqs.BeginRead, AddressOf rqs.EndRead, buffer, 0, bufferSize, Nothing)
            bytesTotal += bytesRecieved
            fs.Write(buffer, 0, bytesRecieved)

            Dim m_Bytes As String = "Downloading " & (Convert.ToDouble(bytesTotal) / 1048576).ToString("0.00") & " MB" & "  /  " & (Convert.ToDouble(pBar.Maximum) / 1024 \ 1024).ToString("0.00") & " MB"
            pLabel.Text = m_Bytes
            pBar.Increment(bytesRecieved)

        Loop Until bytesRecieved = 0


        If Not fs Is Nothing Then
            fs.Close()
            fs.Dispose()
        End If

        If Not rqs Is Nothing Then rqs.Close()
        If Not resp Is Nothing Then resp.Close()

        frmSetup.lbl_localDB_Title.Text = "Installing Microsoft SQLLocalDB.msi"
        pLabel.Text = "Installing SQLLocalDB - Please Wait"
        pBar.Value = 0

        'Install the Microsoft LocalDB Software
        Using localDB As Process = New Process()

            Dim localDB_PS As New ProcessStartInfo
            localDB_PS.FileName = desktop_Save
            localDB.EnableRaisingEvents = True
            AddHandler localDB.Exited, AddressOf localDB_Exited

            localDB.StartInfo = localDB_PS
            localDB.Start()

            Do
                'Do Nothing, just wait and enjoy the ride
                If Not localDB.HasExited Then
                    pBar.Value = If(pBar.Value < 99, pBar.Value = pBar.Value + 0.1, 0)
                End If

            Loop While Not localDB.WaitForExit(1200000)

        End Using

        Return bytesTotal

    End Function
    Private Sub localDB_Exited(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Your code goes here
    End Sub

End Class


Sorry for all the code, Just wanted to make sure the picture was complete, I rarely post this much code.
AnswerRe: Proper us of await Pin
Richard Deeming15-Dec-14 2:37
mveRichard Deeming15-Dec-14 2:37 
GeneralRe: Proper us of await Pin
jkirkerx16-Dec-14 7:11
professionaljkirkerx16-Dec-14 7:11 
Questionwrite the buffer to the drive Pin
jkirkerx13-Dec-14 18:58
professionaljkirkerx13-Dec-14 18:58 
AnswerRe: write the buffer to the drive [Got It] Pin
jkirkerx14-Dec-14 8:08
professionaljkirkerx14-Dec-14 8:08 
SuggestionCalculating time gap b/w files in MSFlexgrid Pin
Member 1042199813-Dec-14 3:32
Member 1042199813-Dec-14 3:32 
GeneralRe: Calculating time gap b/w files in MSFlexgrid Pin
Richard MacCutchan13-Dec-14 4:14
mveRichard MacCutchan13-Dec-14 4:14 
QuestionGridview problems with Entity framework Pin
dilkonika11-Dec-14 16:56
dilkonika11-Dec-14 16:56 
AnswerRe: Gridview problems with Entity framework Pin
Dave Kreskowiak11-Dec-14 17:00
mveDave Kreskowiak11-Dec-14 17:00 
GeneralRe: Gridview problems with Entity framework Pin
dilkonika13-Dec-14 6:17
dilkonika13-Dec-14 6:17 
GeneralRe: Gridview problems with Entity framework Pin
Dave Kreskowiak13-Dec-14 7:40
mveDave Kreskowiak13-Dec-14 7:40 
Questiondialog, top level vs mdiparent Pin
jkirkerx11-Dec-14 11:56
professionaljkirkerx11-Dec-14 11:56 
AnswerRe: dialog, top level vs mdiparent [settled] Pin
jkirkerx11-Dec-14 13:32
professionaljkirkerx11-Dec-14 13:32 
AnswerRe: dialog, top level vs mdiparent Pin
Dave Kreskowiak11-Dec-14 13:41
mveDave Kreskowiak11-Dec-14 13:41 
GeneralRe: dialog, top level vs mdiparent Pin
jkirkerx11-Dec-14 13:48
professionaljkirkerx11-Dec-14 13:48 
GeneralRe: dialog, top level vs mdiparent Pin
Dave Kreskowiak11-Dec-14 14:44
mveDave Kreskowiak11-Dec-14 14:44 
GeneralRe: dialog, top level vs mdiparent Pin
jkirkerx11-Dec-14 16:37
professionaljkirkerx11-Dec-14 16:37 
GeneralRe: dialog, top level vs mdiparent Pin
Dave Kreskowiak11-Dec-14 16:58
mveDave Kreskowiak11-Dec-14 16:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.