• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

Waiting

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
gvector1
Asked:
gvector1
  • 4
  • 2
2 Solutions
 
gregoryyoungCommented:
lock(someobject) { do code; }
0
 
eternal_21Commented:
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
 
gregoryyoungCommented:
I would personally not use a windows timer though and instead use a System.Threading.Timer ... this would resolve the issue immediately.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
gregoryyoungCommented:
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
 
eternal_21Commented:
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
 
gvector1Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now