Check Internet Speed test VB.NET - vb.net

I'm trying to check internet speed from vb.net app.
I've tried this code but it does not give me correct information.
Dim netI() As NetworkInterface = NetworkInterface.GetAllNetworkInterfaces
Label3.Text = netI(0).Speed
Label3.Text = Label3.Text / 1048576
Whats basicly i need is to know my internet speed test download in mbps

There is a logic to figure it by your self.
First you find out a file which can be downloaded from internet.
Then convert the file size into Megabits or Kilobits. The format you want to measure (Mbps or Kbps)
You know the download speed is measured Megabits per second or Kilobits per second
First capture the start time
DateTime startTime = DateTime.Now
Down load the file
Dim web_client As WebClient = New WebClient
web_client.DownloadFile("URL", filename)
Now capture the end time.
DateTime endTime = DateTime.Now
Now you can calculate the download speed by using math functions.
= file size/(start Time In Seconds-end Time In Seconds)
Notes: Use only DownloadFile of WebClient. Because this method blocks while downloading the file. Do not use DownloadFileAsync.

Related

vb.net check if file being fully copied before moving this file to backup directory

I have a video recording software that will record video files in directory. and I am writing vb.net code to move finished files into another directory ( external hard disk).
I only move files which have been finished recording.
I need only to move files which are finished recording. The problem is my code move files that are still being recorded.
my question : how I can check if a file is not being recorded right now ?
Thanks
In the following code you'll know best how long since the file was written indicates finished.
Dim di As New IO.DirectoryInfo(dirPath)
Dim noMod As New TimeSpan(0, 2, 0) 'last write time
Dim _movTM As DateTime = DateTime.Now.Add(-noMod)
For Each fi As IO.FileInfo In di.GetFiles
If fi.LastWriteTime < _movTM Then
'move here
End If
Next

Download many small files with FTP quickly

I have a working code to download many files (hundreds) from an FTP server, but it's very slow and often a timeout error appears.
This is my current way of doing the downloads:
Using ftpClient As New WebClient()
ftpClient.Credentials = New System.Net.NetworkCredential(ftpuser, ftppassword)
For i As Integer = 0 To directoriesDownload.Count - 1
If directoriesDownload(i).Contains(".") Then
If Sync_BackgroundWorker.CancellationPending = True Then
Exit Sub
End If
Dim path As String = "ftp://" & ftpserver & "Datenbank/" + directoriesDownload(i).ToString()
Dim trnsfrpth As String = config.rootpath & "ServerDownload\" + directoriesDownload(i).ToString()
ftpClient.DownloadFile(path, trnsfrpth)
filenametodownload = directoriesDownload(i).ToString()
filesdownloaded += 1
Sync_BackgroundWorker.ReportProgress(filesdownloaded)
End If
Next
ftpClient.Dispose()
End Using
Is there any faster way of downloading hundreds of small files (up to 10 KB) from an FTP server in VB.NET?
It would be the best if there is an option to sign into the FTP only once instead of logging in and out for every file.
I found somebody else having the same problem but without a working result:
Using FTP to download each file *WHILE* getting the file list
I also tried multithreading with a Parallel.For loop, but WebClient does not work with multithreading. Same thing if I try with ftpClient.DownloadFileAsync(New Uri(path), trnsfrpth).
Is there any faster way of downloading hundreds of small files (up to 10 KB) from an FTP server in VB.NET?
...
I also tried multithreading with a Parallel.For loop, but WebClient does not work with multithreading. Same thing if I try with ftpClient.DownloadFileAsync(New Uri(path), trnsfrpth).
Multithreading is the way to go. It's not true that WebClient does not support multithreading. Why wouldn't it?
If you have a problem with implementing multithreaded FTP transfers, you should ask a question about that, rather than asking a question about other (and probably non-existent) ways.
It would be the best if there is an option to sign into the FTP only once instead of logging in and out for every file.
Your code does sign into FTP only once.
See C# - FtpWebRequest - Multiple requests over the same connection/login - What is written there about FtpWebRequest is equally true for WebClient, as WebClient uses FtpWebRequest internally.

Save and retrieve multiple videos to local storage?

I'm using the sample app from microsoft here:
http://msdn.microsoft.com/en-us/library/hh394041(v=vs.92).aspx
as a starting point to develop an app that allows the user to record multiple videos in the app to a collection.
What is the best way to accomplish this? I noticed that the example uses a fileSink object to specify the capture source and file name in isolated storage.
Private Sub StartVideoRecording()
Try
' Connect fileSink to captureSource.
If captureSource.VideoCaptureDevice IsNot Nothing AndAlso captureSource.State = CaptureState.Started Then
captureSource.Stop()
' Connect the input and output of fileSink.
fileSink.CaptureSource = captureSource
fileSink.IsolatedStorageFileName = isoVideoFileName
End If
' Begin recording.
If captureSource.VideoCaptureDevice IsNot Nothing AndAlso captureSource.State = CaptureState.Stopped Then
captureSource.Start()
End If
' Set the button states and the message.
UpdateUI(ButtonState.Recording, "Recording...")
' If recording fails, display an error.
Catch e As Exception
Me.Dispatcher.BeginInvoke(Sub() txtDebug.Text = "ERROR: " & e.Message.ToString())
End Try
End Sub
How would I then query that collection and allow the user to select that video for viewing in a listview? Is there no way to specify a folder to keep the video files organized?
Just looking for some advice on best practices to get this done. I wanted to use a video chooser that would allow the user to choose a video from their photo roll, but Windows Phone doesn't currently allow this.....
Well, is there any need to use a folder? noone can browse the ISO storage, so I see no need for folders :).
Using that tutorial, two files are created: "CameraMovie.mp4" and "CameraMovie.mp4.jpg" (the jpg is at least created on my phone, use ISETool to see the content of the ISO storage).
To record multiple videos, you would have to rename the filename each time
private string isoVideoFileName = "CameraMovie.mp4";
// reset the name when the recording starts
isoVideoFileName = DateTime.Now.ToString("yyyy-MM-dd_HH_mm") + ".mp4";
just change that variable when you start recording.
At the end of each recording, add the name of the video to a list, and once a video is added, you save the list (also to the ISO storage).
While loading the app, you load the list from the ISO, use the jpg's to make video tiles (or w/e you wanna do with it ;))
Hope this will help you a little forward, if not you have found the solution yet.
note, im sorry for using C#, whereas you use VB. It is however that i dont know VB well enough to type it at will ;)

program logic to speed up processing

I have setup an application to parse about 3000 files a day where each contains around 4000-5000 posts in xml format with like 100 fields.
It involves a lot of cleanup and parsing but on average it takes around 6 seconds per post. Now I tried threading but because of the way I have everything set up with variables being overwritten etc...I have divided the files into different folders and just created copies of the program to run and access the assigned folder. It is running on a windows 2008 server with 16 G of memory and I am told I need to reprogram to speed up the process and also not use so much memory.
Does anyone have any suggestions or does this process I have set up seem fine? I am the new guy and literally everyone thinks I am an idiot.
For i As Integer = 0 To fileLists.Count - 1
Do
Try
If Not completeList.Contains(fileLists(i).ToString) AndAlso fileLists(i).EndsWith("xml") Then
If fileLists(i).Contains("Fa") Then
inputFile = New StreamReader(fileLists(i))
data = String.Empty
infile = fileLists(i).ToString
swriter.WriteLine(infile.ToString)
swriter.Flush()
Dim objFileInfo As New FileInfo(fileLists(i))
fileDate = objFileInfo.CreationTime
Dim length As Integer = objFileInfo.Length
data = inputFile.ReadToEnd
If Not data Is Nothing Then
parsingTools.xmlLoad(data)
tempList.Add(fileLists(i))
completeList.Add(fileLists(i))
End If
inputFile.DiscardBufferedData()
End If
End If
End If
Ok I am not sure what code to post because there is literally a lot of code. The above is the main module and onece it reads in data it tries to load it into xml document, if it fails it parses it using ordinary text parsing. It navigates to each field I need to extract and also connects to a couple of web services to get more content before all this is added together to create a new xml file.
manager.AddNamespace("x", "http://www.w3.org/2005/Atom")
manager.AddNamespace("a", "http://activitystrea.ms/spec/1.0/")
Dim nodecount As Integer = xmlParser.getNodesCount(navigator, "x:entry", manager)
For i As Integer = 1 To nodecount
statid = xmlParser.XPathFind(navigator, "x:entry[" & i & "]/x:id", manager)
contentDate = xmlParser.XPathFind(navigator, "x:entry[" & i & "]/x:published", manager)
template = xmlParser.XPathFind(navigator, "x:entry[" & i & "]/x:title", manager)
title = xmlParser.XPathFind(navigator, "x:entry[" & i & "]/x:source/x:title", manager)
ctext = xmlParser.XPathFind(navigator, "x:entry[" & i & "]/x:summary", manager)
htext = xmlParser.XPathFind(navigator, "x:entry[" & i & "]/a:object/x:content", manager)
author = xmlParser.XPathFind(navigator, "x:entry[" & i & "]/x:author/x:name", manager)
authorUri = xmlParser.XPathFind(navigator, "x:entry[" & i & "]/x:author/x:uri", manager)
avatarUrl = xmlParser.XPathFind(navigator, "x:entry[" & i & "]/a:author/x:link[#rel='avatar']/#href", manager)
Next
The problem with something like this is the hard drive itself - depending upon many factors it can act as a funnel and essentially constrict the number of files you are able to interact with on the drive concurrently.
With that said, I'd highly recommend you take a look at the TPL (task parallel library) in .NET v4.0. It's a framework that vastly simplifies the act of "spreading the work across all the available cores" of your processors. My computer has dual processors, each with 4 native cores (Intel Xeon's # 3GHz) which gives me 8 cores. I have an application that downloads ~7,800 different URL's off the net and analyzes their content. Depending on the values it finds it will do some additional processing then store the results. This is somewhat similar to your situation in that we both share a restricting resource (for me it's the network) and we have to manually parse and evaluate the contents of the files we're working with.
My program used to take between 26 to 30 minutes (on average) to process all those files. This was using a properly implemented multithreaded application. By switching the code over to the TPL it now only takes 5 minutes. A HUGE improvement.
Take a look at the TPL and plan on having to make some changes to your code in order to maximize the potential improvements. But, the payoff can be fantastic if done correctly.
Does the application run continuously as a service or is it something you run once/or few times a day? If it doesnt run continuously you could try that and limit the processing to a few concurrent threads.

how to open a vb.application from another vb.application with parameters

i have 2 vb applications. this is the code for the first one which when a button is clicked it will check if the other application is already open. If not, it'll open that application -
Dim sComputer As String
sComputer = Environ("COMPUTERNAME")
Dim LocalByName As Process() = Process.GetProcessesByName("ticket.prices", sComputer)
If LocalByName.Length = 0 Then
System.Diagnostics.Process.Start("http://ticket.prices.application")
End If
this runs fine. but what i need is that the customerid on the application 1 that is calling application 2, should be transfered while opening app 2.
e.g -
Customer 10001 screen is open on app 1. When i click open app 2, the above code runs and opens app 2. how do i make app 2 open to customer 10001 screen. Is there any way to pass parameters while opening app 2 in System.Diagnostics.Process.Start ?
Use the version of 'Process.Start' that takes 2 strings, the second being the commandline parameters. See here for details.
You want the ProcessStartInfo class, or use the Start method taking to strings. ProcessStartInfo gives you a lot of options about how to start your program, which often comes in handy. Its good to get familiar with it.
Dim info as New ProcessStartInfo()
info.Arguments = "10001"
info.FileName = "exename"
Dim LocalByName as New Process()
LocalByName.StartInfo = info
LocalByName.Start()
Getting the arguments in the new program is accomplished via Environment.GetCommandLineArgs()
For Each arg As String In Environment.GetCommandLineArgs()
Console.WriteLine(arg)
Next arg
It looks like what you ultimately want to accomplish is getting the currently selected row from App 1 and passing that to the second program, though. Is this correct? That opens a whole new ball of wax involving interprocess communication.
EDIT: The simplest way to get the selected edit would be to write the id out to a text file. You have to be careful when doing this because if you just write System.IO.File.WriteAllText("selectedrow.txt", "123"), you'll write to the app's startup path directory. You'll want to get the exe's current path as below
Dim u as New Uri(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
dim exepath as String = System.IO.Path.GetDirectoryName(u.LocalPath)
dim fullPath as String = System.IO.Path.Combine(exepath, "selectedrow.txt")
System.IO.File.WriteAllText(fullpath, "123")
This will overwrite the text in the file every time you change rows. You want to wrap this in a try/catch block so as not to crash the program. Make sure you log the errors; don't just swallow them. To read the data, you just do
dim id as string = System.IO.File.ReadAllText(PathToFileYoureWritingToInTheOtherProgram)
in the other program.
This isn't necessarily the best way to go about things, but its the simplest way I know of off the top of my head.
You might could look at MessageQueues if you a better solution, but as long as you're not changing selected rows every 100ms, writing the file should work fine.