Click here to Skip to main content
15,885,537 members
Home / Discussions / C#
   

C#

 
GeneralDataAdapters Pin
MrJJKoolJ28-Jan-04 13:54
MrJJKoolJ28-Jan-04 13:54 
GeneralRe: DataAdapters Pin
Christian Graus28-Jan-04 15:47
protectorChristian Graus28-Jan-04 15:47 
GeneralRe: DataAdapters Pin
MrJJKoolJ28-Jan-04 16:22
MrJJKoolJ28-Jan-04 16:22 
GeneralRe: DataAdapters Pin
Christian Graus28-Jan-04 16:27
protectorChristian Graus28-Jan-04 16:27 
GeneralControls using the form designer Pin
James Simpson28-Jan-04 12:12
James Simpson28-Jan-04 12:12 
GeneralRe: Controls using the form designer Pin
James Simpson28-Jan-04 12:28
James Simpson28-Jan-04 12:28 
Generalthreding Pin
nadeen ali28-Jan-04 10:56
nadeen ali28-Jan-04 10:56 
GeneralRe: threding Pin
Heath Stewart28-Jan-04 11:32
protectorHeath Stewart28-Jan-04 11:32 
For information on thread synchronization, see the documentation for the System.Threading namespace in the .NET Framework SDK, specifically information about the Monitor (or use the lock keyword in C#) class which is the easiest to use (but not always appropriate). I also urge you to search this forum (use "Search Comments" above) and the CodeProject site for many examples and discussions. There have been several here in the C# forum similar to your problem in the recent past.

When using the lock keyword, the C# compiler generates the following:
// Source
lock(someObject)
{
  Console.WriteLine("Hello, world!");
}
 
// Compiled
Monitor.Enter(someObject)
try
{
  Console.WriteLine("Hello, world!");
}
finally
{
  Monitor.Exit(someObject);
}
someObject is an instance of an object and its scope depends on your requirements. Since you're synchronizing methods on different objects, you should use a static object like the Type of your class. So, if your class is called MyClass, then use lock(typeof(MyClass)) to make sure all threads are synchronized no matter which object is trying to access a resource (like your array). If you want to synchronize a resource that is specifically to a single instance of a class, then you can lock against this.

If you look at the namespace I mentioned before, there are many other synchronization objects that allow you to specify time-outs, share WaitHandles, and more. There's also a topic in the .NET Framework SDK that should get you started: http://msdn.microsoft.com/library/en-us/cpguide/html/cpconthreading.asp[^].

 

-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
GeneralProtecting a CD or DVD from copy Pin
antoine@orchus-tech28-Jan-04 10:05
antoine@orchus-tech28-Jan-04 10:05 
GeneralRe: Protecting a CD or DVD from copy Pin
Heath Stewart28-Jan-04 11:24
protectorHeath Stewart28-Jan-04 11:24 
GeneralRe: Protecting a CD or DVD from copy Pin
Kentamanos28-Jan-04 11:28
Kentamanos28-Jan-04 11:28 
QuestionHow to record keyboard Pin
jacal9928-Jan-04 9:25
jacal9928-Jan-04 9:25 
AnswerRe: How to record keyboard Pin
Mazdak28-Jan-04 9:43
Mazdak28-Jan-04 9:43 
GeneralRe: How to record keyboard Pin
jacal9928-Jan-04 9:54
jacal9928-Jan-04 9:54 
GeneralTextBox Capture property is automatically set to false Pin
Manobal28-Jan-04 8:27
Manobal28-Jan-04 8:27 
GeneralRe: TextBox Capture property is automatically set to false Pin
Heath Stewart28-Jan-04 11:34
protectorHeath Stewart28-Jan-04 11:34 
GeneralRe: TextBox Capture property is automatically set to false Pin
Manobal28-Jan-04 12:18
Manobal28-Jan-04 12:18 
GeneralRe: TextBox Capture property is automatically set to false Pin
Heath Stewart28-Jan-04 12:21
protectorHeath Stewart28-Jan-04 12:21 
Generalon which port the applacition is running Pin
obaidullah28-Jan-04 8:00
obaidullah28-Jan-04 8:00 
GeneralRe: on which port the applacition is running Pin
Heath Stewart28-Jan-04 11:43
protectorHeath Stewart28-Jan-04 11:43 
GeneralFrontPage Web Connection Pin
Adam Hable28-Jan-04 7:27
Adam Hable28-Jan-04 7:27 
GeneralRe: FrontPage Web Connection Pin
Heath Stewart28-Jan-04 11:39
protectorHeath Stewart28-Jan-04 11:39 
GeneralRe: FrontPage Web Connection Pin
Adam Hable28-Jan-04 15:36
Adam Hable28-Jan-04 15:36 
GeneralRe: FrontPage Web Connection Pin
Heath Stewart29-Jan-04 2:18
protectorHeath Stewart29-Jan-04 2:18 
GeneralRe: FrontPage Web Connection Pin
Adam Hable29-Jan-04 4:02
Adam Hable29-Jan-04 4:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.