threads (static class)

  • Thread starter csharpula csharp
  • Start date
C

csharpula csharp

Hello,

I would like to know how can I insure this:

static Class A

{

calling methodA
calling methodB

}

And I need to insure that method B will run after method A and no other
thread will perform something with Class A instance in the middle. What
is the best way?

Thank you!
 
N

not_a_commie

In order for you to get help, code a more complete example. Write out
the method stubs.
 
N

Nick

csharpula said:
Hello,

I would like to know how can I insure this:

static Class A

{

calling methodA
calling methodB

}

And I need to insure that method B will run after method A and no other
thread will perform something with Class A instance in the middle. What
is the best way?

Thank you!

This is a way. It is the simplest way but has what maybe a serious
potential problem. Additionally to what you wanted MethodC and MethodD
lock out each other on a static lock object which may be a problem. If
you don't want this to happen I think you are going to need a couple of
booleans and use pulse and wait or maybe just multiple lock objects.


class ClassA
{
private static readonly
Object syncLock = new Object();
private static void methodA()
{
...
}
private static void methodB()
{
...
}

public static void methodC()
{
lock (syncLock)
{
methodA();
methodB();
}
}

public void methodD()
{
lock (syncLock)
{
...
}
}
public void methodE()
{
lock (syncLock)
{
...
}
}
}
 
P

Pavel Minaev

I would like to know how can I insure this:

static Class A

{

  calling methodA
  calling methodB

}

And I need to insure that method B will run after method A and no other
thread will perform something with Class A instance in the middle. What
is the best way?

There's no class A instance in the code above, since class A is
static; static classes have no instances.

Please explain in more detail what you're actually trying to do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top