DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Is This a Good Idea (use App var)?

  1. #1
    Join Date
    Jan 2007
    Posts
    3

    Is This a Good Idea (use App var)?

    Thank you for reading this.

    There's a web service that's being called no more
    than 4 times a week and it must process that each time call.
    Each call, the caller will only call once and assumes
    that the web service is processing X.

    How do you make the web service synchronize (one at time)
    and be sure to process X whenever it's being called?

    One idea is to create an Application variable that
    holds if web service is processing.

    So, in the web service method:

    Main sub ()

    'First thing it does is check the Application var
    'to see if it's already processing something.
    'If it's processing X then it will just be in an endless loop.

    While IsProcessing ()
    'do nothing
    Next

    'Once another web service instance stops processing X,
    'it will change the application var to FALSE.

    'The Second thing it does is change the App var to False
    'b/c it will start processing X.

    blah processing X
    blah processing X
    blah processing X


    'The last thing it does is change the App var back to FALSE

    End Sub

    Of course I'll try to catch an exception if thrown and change
    the App var back to FALSE before terminating the process.

    If somehow it falls through the crack and doesn't change App var
    back to FALSE do I reboot stop/restart IIS or reboot the server?

    How will you know if the web service processed X unless it
    writes to a datasource indicating that it did before the
    method exists, right?

    Or is there a better way of handling this situation?

  2. #2
    Join Date
    Mar 2004
    Posts
    78
    HI,

    I am not aware of the VB or C# thread synchronization part of the libraries but it is a BAD idea to use endless loops. You have a tipical thred synchronisation problem and you solve it by using a monitor or a semaphor.

    In your case you need to provide that a single process is running and all of the rest are suspended until the running one exits the critical section.

    You can use a semaphor that changes its state to up when a process is active and aquires a lock on it. From this moment further any process that request a lock on it will block until the lock is released(by the already running process).

    When the running proces finishes it will unlock the semaphor, the suspended processes or threads will be resumed and the next process that aquires the lock will run through the critical section and all of the rest will be blocked.
    Which of the resumed threads will be next depends on configuration or implementation but it should not matter.

    If you use an endless loop you waste CPU time.

    WS run over HTTP so the request on huge calclualtion or severe hit may timeout so be sure to check if it should be served at all after a process enters the critical section.

    I hope that this will be useful for you

  3. #3
    Join Date
    Jan 2007
    Posts
    3
    Thanks NewUniverse -- your comments are very helpful.

    I'm having doubts of having a WS. I'm leaning more towards having
    a Windows service, instead. I can process one file at time and it's more fault-tolerant.

    Thanks again!

Similar Threads

  1. Does Pockect PC and IE mean Mobile Wep App?
    By Greg Rothlander in forum ASP.NET
    Replies: 2
    Last Post: 11-23-2002, 02:31 AM
  2. App Object
    By Rob Teixeira in forum .NET
    Replies: 15
    Last Post: 05-31-2002, 03:30 PM
  3. Replies: 0
    Last Post: 09-26-2000, 09:52 AM
  4. Re: discover whether VB App is in Run mode.
    By Michael Culley in forum VB Classic
    Replies: 3
    Last Post: 09-17-2000, 11:53 PM
  5. Find out if my app is the active app
    By Leonardo Bosi in forum VB Classic
    Replies: 2
    Last Post: 05-04-2000, 03:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center