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. C#
  4. The Web Service FREEZE the App

The Web Service FREEZE the App

Scheduled Pinned Locked Moved C#
questiondotnetdesignhelptutorial
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.
  • L Offline
    L Offline
    laphijia
    wrote on last edited by
    #1

    I have a program that connects to a Web Service to authenticate a user. When the user clicks ok the program access the Web Service through the internet. This actually seems to FREEZE the program until it has finished, how can I solve this problem? It's really not a good user interface like now! I mean maybe I could make like when you are loggin in in MSN Messenger, but how to do it? Thankx! "Nelle cose del mondo non e' il sapere ma il volere che puo'."

    J 1 Reply Last reply
    0
    • L laphijia

      I have a program that connects to a Web Service to authenticate a user. When the user clicks ok the program access the Web Service through the internet. This actually seems to FREEZE the program until it has finished, how can I solve this problem? It's really not a good user interface like now! I mean maybe I could make like when you are loggin in in MSN Messenger, but how to do it? Thankx! "Nelle cose del mondo non e' il sapere ma il volere che puo'."

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      What you are seeing is that all the work is being done on one thread, including all the waiting that you have to do while you wait for the webservice to respond. The solution is to use an Async method or a separate thread. The Async method will use a separate thread but it takes care of all the work for you; while you have to do all the work to use a thread yourself. If I remember correctly the code that the "Add Web Reference" option generates includes some Async methods. The Async methods begin with Begin and End followed by the name of the method. Using a method from the CodeProject webservice ArticleBrief[] GetLatestArticleBrief(int NumArticles); The Async versions of this method are: IAsyncResult BeginGetLatestArticleBrief(int NumArticles, AsyncCallback callback, object asyncState); and ArticleBrief[] EndGetLatestArticleBrief(IAsyncResult asyncResult); Typical usage is as such

      IAsyncResult iar = BeginGetLatestArticleBrief(numArticles, null, null);

      // Later on
      if( iar.IsCompleted )
      {
      articleBriefs = EndGetLatestArticleBrief(iar);
      }
      else
      {
      // do something else
      }

      Since you wouldn't be doing anything else while the user is logging in I would do this:

      IAsyncResult iar = BeginLoginUser(username, password, null, null);

      while( !iar.IsCompleted )
      {
      Application.DoEvents(); // Let the message pump do some work
      }

      // Continue as before

      This is only a brief intro and a limited way of doing things, MSDN contains an entire section on Asynchronous programming which you should read before going much further. If you use the MSDN that came with VS.NET I found the topic by going to the following nodes: Visual Studio.NET -> .NET Framework -> Programming with the .NET Framework -> Including Asynchronous Calls HTH, James "Java is free - and worth every penny." - Christian Graus

      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