Solved

Waiting

Posted on 2004-08-27
7
221 Views
Last Modified: 2011-04-14
Quick Question,

I have an application that has an event.  Within that event I call a method.  What I am needing to do is to wait for that method to finish before continuing with the code.  Ex.  An event happens that triggers the event 3 times within 10 seconds.  The problem is that the method I call from the event might take longer than 10 seconds.  How can I hold up the event handling until the method is done processing the code??????????

Thanks,
Kendal
0
Comment
Question by:gvector1
  • 4
  • 2
7 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 250 total points
ID: 11917812
lock(someobject) { do code; }
0
 
LVL 10

Assisted Solution

by:eternal_21
eternal_21 earned 250 total points
ID: 11917862
Another way to do it is to use the MethodImplAttribute

  [System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.Synchronized)]
  static void MyMethod()
  {
    // MyMethod Implementation
  }

on a method that you only want to be run by one thread at a time.
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11917891
I would personally not use a windows timer though and instead use a System.Threading.Timer ... this would resolve the issue immediately.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11917925
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11917949
eternal: isnt the MethodImplAttribute GREAT for subclassing synchronized wrappers :) it took me a while to figure out why MS use the .Synchronized pattern until I found that.
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 11918561
gregoryyoung, You know I never knew it existed until I came across a Java vs C# article a while back (http://www.25hoursaday.com/CsharpVsJava.html#synchronization)! :)
0
 

Author Comment

by:gvector1
ID: 11996613
Thanks guys,
I will split the points between the two of you since both methods will work and you both were extremely helpful.  Very helpful pointers.

Thanks again,
Kendal
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question