Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Synchronous Static Method on Same Thread 1

Status
Not open for further replies.

sammye

Programmer
Oct 5, 2007
35
US
Hello,

How do I go about making a static method synchronous? I have a static method which gets called by multiple UI events, but I want the last one to complete before the latest call gets processed.

I tried to use 'lock', but only to find out that it only blocks between separate threads. Any hints/suggestions/pointers? Thanks.
 
The ThreadPool class may do the work. It's a static class that handles your threads. You can specify the maximum number of concurrent threads to run using SetMaxThreads() (in your case, you want 1 I believe), and you queue threads using QueueUserWorkItem().

The documentation for the class can be found:
A drawback of the class is that you have little control over the threads, such as being unable to suspend or abort running threads. See if the ThreadPool class satisfies your request.

|| ABC
 
Thanks, I've heard of thread pools, but have little understanding of them so I'll do a little digging. For now, I got around the issue by putting the method into its own thread - I'm guessing that this may be similar to what you suggested.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top