Posted on 2004-08-27
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??????????

Question by:gvector1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 37

Accepted Solution

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

Assisted Solution

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

  static void MyMethod()
    // MyMethod Implementation

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

Expert Comment

ID: 11917891
I would personally not use a windows timer though and instead use a System.Threading.Timer ... this would resolve the issue immediately.
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

LVL 37

Expert Comment

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.
LVL 10

Expert Comment

ID: 11918561
gregoryyoung, You know I never knew it existed until I came across a Java vs C# article a while back (! :)

Author Comment

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,

Featured Post

Industry Leaders: 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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

707 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