?
Solved

How do I prevent two threads from running the same static method at the same time?

Posted on 2011-10-03
1
Medium Priority
?
220 Views
Last Modified: 2012-05-12
How do I prevent two threads from running the same static method at the same time?
0
Comment
Question by:deleyd
1 Comment
 
LVL 7

Accepted Solution

by:
OklahomaDave earned 2000 total points
ID: 36906730
You can lock the thread just as it makes the call, and .NET will automatically serialize the calls.

private static object lockObject = new Object();

public static SomeMethod()
{
    lock(lockObject)
    {
       //do your stuff
    }
}
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

829 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