-1

I'm trying to make a very simple updater app that reads current version.txt file contents and checks if it's the same or greater (in which case update starts).

This post helped me make a working app, but it causes a significant pause in my main app. Could it work faster or is there an easier way to load text from online .txt file?

UPD: for some reason the ~15 second lag only happens at first run, all consequent DownloadStrings work as fast as they should until the app is closed.

Community
  • 1
  • 1
user1306322
  • 8,561
  • 18
  • 61
  • 122
  • Can you run it as an asynchronous request whilst you're doing something else? – Rup May 04 '12 at 15:26
  • I would rather not do it, or it can look like the app is up to date, user starts working and after some time he gets notification that the version is outdated and all progress made will be incompatible with current version. – user1306322 May 04 '12 at 15:28
  • 'after some time' will probably be within a few seconds, won't it? Do you have a splash screen - can you run it asynchronously with your splash screen? If the delay is loading the wininet engine then you could instead just make a socket call to the web server with a simple HTTP request in it and avoid wininet, but then you'd have to deal with proxy servers etc. yourself which wininet just handles for you. – Rup May 04 '12 at 15:34
  • No splash screens, the app opens and the user starts work instantly. It's about fifteen seconds, the time varies, and changing things within the app while the version is being downloaded could do nothing if it's outdated. Also I don't have any idea what you mean, could you write an example? – user1306322 May 04 '12 at 15:39
  • Won't you also have the same problem if a user keeps a client running whilst you update the server - they'll be working with an out-of-date incompatible client? How do you solve that one? OK, I'll try and write something. – Rup May 04 '12 at 15:44
  • How long does something like client.DownloadString("http:///www.google.com/index.html") take? (Note, there is only supposed to be two blackslashes before the www.google.com) – sgmoore May 04 '12 at 16:46
  • What happens if you use 173.194.66.103 instead of www.google.com ? – sgmoore May 04 '12 at 17:07
  • Excatly the same. I don't think it's about resolving. – user1306322 May 04 '12 at 17:16
  • Strange. I tested this in Linqpad and it took about 300 ms. Can you test this on another computer or outside your network? – sgmoore May 04 '12 at 17:23
  • Other computers show the same result. First press of the button takes ~15 seconds and consequent presses are near instant. – user1306322 May 04 '12 at 17:42

4 Answers4

2

You won't be able to magically make the download faster. Instead, I recommend you execute the download on a separate thread so the user can use your app without waiting.

usr
  • 168,620
  • 35
  • 240
  • 369
0

You can try

WebClient client = new WebClient();
client.DownloadFile(url, fileName); 

And what do you mean the significant pause? Is the response time of the server you tried to fetch .txt file?

fankt
  • 1,007
  • 1
  • 7
  • 16
  • I don't really know what exactly causes the pause, because the host from which the text file is fetched is fast and the file itself is very small. – user1306322 May 04 '12 at 15:29
  • Either you didn't pin point the write location of your "delay" or else your connection is simply slow. Try to measure where the "delay" happens. – Styxxy May 04 '12 at 15:33
  • `DownloadFile` works as slowly as `DownloadString`, unfortunately. I can't figure out where the delay is coming from. VS profiler doesn't show performance spikes or anything, it just hangs for some time, that's it. – user1306322 May 04 '12 at 15:36
  • Because they are the same thing basically. And I am curious about how long does it hangs? – fankt May 04 '12 at 15:39
  • 13 to 15 seconds by `Stopwatch`. – user1306322 May 04 '12 at 15:46
0

This could help you to make you app faster:

Oscar Jara
  • 14,129
  • 10
  • 62
  • 94
  • 2
    Why would a console application make a webclient request faster than a forms app? – Rup May 04 '12 at 15:37
  • @Rup Not exactly a webclient request, everything. But for some cases this is useful (console apps) for others not, read this: http://stackoverflow.com/questions/2628164/do-console-apps-run-faster-than-gui-apps – Oscar Jara May 04 '12 at 15:39
  • [But the accepted answer](http://stackoverflow.com/a/2628228) says they generally don't, doesn't it? Would message loop processing really have a significant impact on a web request? – Rup May 04 '12 at 15:47
  • @Rup read carefully the long answer of the accepted answer and for this case I think that can be used because it is just a simple app that captures texts from the net. – Oscar Jara May 04 '12 at 15:49
  • 1
    While the request is being handled, the app hangs (form stops redrawing) anyway. – user1306322 May 04 '12 at 15:55
  • @user1306322 that's why a console app is faster (for doing things as you want and avoid redrawing) but If you read the explanation of http://stackoverflow.com/questions/2628164/do-console-apps-run-faster-than-gui-apps "a console application would still be contending for the CPU with other processes in the system". – Oscar Jara May 04 '12 at 16:00
  • I don't get it — while getting the file, the app stops redrawing automatically, so the redrawing does not consume resources while the main process of this question is being run. Redrawing itself doesn't consume any significant amount of resources. I'm not sure if it's on-topic. – user1306322 May 04 '12 at 16:07
  • @user1306322 Try making a console app in c# and see the difference. – Oscar Jara May 04 '12 at 16:11
  • 1
    @OscarJara exactly the same time as forms app — 13 seconds. – user1306322 May 04 '12 at 16:21
  • @user1306322 that's because you're blocking the UI thread - you should do non-UI work on a background thread – Rup May 04 '12 at 19:21
  • No, I disagree - it's simply waiting on a socket so the little UI overhead mentioned in the long answer won't cause a user-perceivable slow-down – Rup May 04 '12 at 19:23
0

The pause was caused by default proxy settings. Solution is in my other question:

WebClient.DownloadString takes about 15 seconds when first called

Community
  • 1
  • 1
user1306322
  • 8,561
  • 18
  • 61
  • 122