Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Waiting

Posted on 2004-08-27
7
Medium Priority
?
227 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 1000 total points
ID: 11917812
lock(someobject) { do code; }
0
 
LVL 10

Assisted Solution

by:eternal_21
eternal_21 earned 1000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Integration Management Part 2
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

972 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