I'm developing a windows store app, and I'm uploading a file to an FTP server with WebRequest, since it was the only work around I could find, with the limitations that I had.

When the application is uploading the video, which takes a few minutes, if the user taps the screen the app will crash. If no input is made, it will work fine.

When I was using Alex Pilotti's FTPS Client DLL, this didn't happen, but I couldn't get the certification for windows store using this DLL.

In my PC, this doesn't happen. It will wait until the video is uploaded and then execute the user input, but in the tablet it's a different story, maybe because it has less processing power/memory, it just crashes.

I was thinking: maybe there is a way to ignore all user input while the upload is happening.

I know it's not the best way, to take control from the user like that, but it would do the job and it would only be for a few minutes.

I've been googling, but I can't find a way to do this.

I'll leave my code below, just in case:

 Public Async Function uploadFile(filename As String, file As StorageFile) As Task(Of Boolean)

        Try
            Dim ftpURL As String = "ftp://111.22.33.444"
            Dim request As WebRequest = WebRequest.Create(ftpURL + "/" + filename)
            request.Credentials = New NetworkCredential("user", "pass")
            request.Method = "STOR"
            Dim buffer As Byte() = Await ReadFileToBinary(filename, file)
            Dim requestStream As Stream = Await request.GetRequestStreamAsync()
            Await requestStream.WriteAsync(buffer, 0, buffer.Length)
            Await requestStream.FlushAsync()
            Return True
        Catch ex As Exception
            Return False
        End Try

    End Function
有帮助吗?

解决方案

I fixed this issue with a very simple line of code:

Await Task.Run(Function() uploadFile(filename, file))

Worked for me.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top