Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. DownloadStringAsync (infinite loop in Release only)

DownloadStringAsync (infinite loop in Release only)

Scheduled Pinned Locked Moved .NET (Core and Framework)
helpquestionannouncementlearning
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    T2102
    wrote on last edited by
    #1

    Can someone tell me why there is an infinite loop below only in release mode? If I add a printf in the while loop, then the infinite loop disappears. for (long i=1; i<(signed)Expiry_URLs.size(); i++) DownloadStringInBackground2(gcnew System::String(Expiry_URLs[i].c_str())); Process_Straddle_View(T, G_OPT, Error_Code); //ASSUMES THAT NO OTHER DOWNLOAD FINISHED BEFORE THIS RUNS while (!!G_OPT.Running); void DownloadStringCallback2( System::Object^ sender, System::Net::DownloadStringCompletedEventArgs^ e ) { // If the request was not canceled and did not throw // an exception, display the resource. --G_OPT.Running; if ( !e->Cancelled && e->Error == nullptr ) { System::String^ textString = dynamic_cast(e->Result); System::Console::WriteLine( textString ); } } void DownloadStringInBackground2( System::String^ address ) { ++G_OPT.Running; System::Net::WebClient^ client = gcnew System::Net::WebClient; System::Uri ^uri = gcnew System::Uri(address); // Specify that the DownloadStringCallback2 method gets called // when the download completes. client->DownloadStringCompleted += gcnew System::Net::DownloadStringCompletedEventHandler( DownloadStringCallback2 ); client->DownloadStringAsync( uri ); }

    D 1 Reply Last reply
    0
    • T T2102

      Can someone tell me why there is an infinite loop below only in release mode? If I add a printf in the while loop, then the infinite loop disappears. for (long i=1; i<(signed)Expiry_URLs.size(); i++) DownloadStringInBackground2(gcnew System::String(Expiry_URLs[i].c_str())); Process_Straddle_View(T, G_OPT, Error_Code); //ASSUMES THAT NO OTHER DOWNLOAD FINISHED BEFORE THIS RUNS while (!!G_OPT.Running); void DownloadStringCallback2( System::Object^ sender, System::Net::DownloadStringCompletedEventArgs^ e ) { // If the request was not canceled and did not throw // an exception, display the resource. --G_OPT.Running; if ( !e->Cancelled && e->Error == nullptr ) { System::String^ textString = dynamic_cast(e->Result); System::Console::WriteLine( textString ); } } void DownloadStringInBackground2( System::String^ address ) { ++G_OPT.Running; System::Net::WebClient^ client = gcnew System::Net::WebClient; System::Uri ^uri = gcnew System::Uri(address); // Specify that the DownloadStringCallback2 method gets called // when the download completes. client->DownloadStringCompleted += gcnew System::Net::DownloadStringCompletedEventHandler( DownloadStringCallback2 ); client->DownloadStringAsync( uri ); }

      D Offline
      D Offline
      Dimitri Witkowski
      wrote on last edited by
      #2

      You have an empty loop here, and it has 'eaten' all your processor in the release mode: while (!!G_OPT.Running); It's not a good way to do such loops for wait until other operation completes. In such cases synchronization must be used, like events, or AsyncCallbacks.

      See my article about Windows 7 Taskbar timer here on CodeProject

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups