Baldwintm

Let me preface this by saying that I am a newb with C#.I am getting the error in the subject above.
here is the code sample :
Code Snippet

class Class1
{
...
public void Method1()
{
Thread.AllocateNamedDataSlot(word);
Thread begin =new Thread(new ParameterizedThreadStart(Class2.method2));
begin.Start(word);
}
}
class Class2
{
...
public void Method2(object w)
{
myWord = (string) w;
LocalDataStoreSlot myTLS;
myTLS=Thread.GetNamedDataSlot(myWord);
Thread.SetData(myTLS, Thread.CurrentThread);
}
}



Both classes are in the same namespace.
Any help would be greatly appreciated.



Re: Visual C# Language "object reference is required for the nonstatic field, method, or property 'Namespace1.Class2.Method2(object)"

Mark Dawson

Hi,

in Method1, you are adding the Class2.Method2 as the method the delegate should call, but this is syntax to call a static method. A static method lives at the class level and is shared by all instances of the class, you need to modify your Method2 signature to include the static keyword i.e.

public static void Method2(object w){ .....

If you don't want to make that static then you will need to create an instance of Class2 inside your Method1 (or somewhere else inside Class1 and pass that to the delegate i.e.

Class2 myClass2 = new MyClass2();

Thread begin =new Thread(new ParameterizedThreadStart(myClass2.Method2));

Mark.






Re: Visual C# Language "object reference is required for the nonstatic field, method, or property 'Namespace1.Class2.Method2(object)"

Baldwintm

Very helpful! That fixed it!
Thank you very much.




Re: Visual C# Language "object reference is required for the nonstatic field, method, or property 'Namespace1.Class2.Method2(object)"

Nama

Hi,

I would like to know how do we access the Microsoft Access records into SQL Server by using Visual C# coding.

Please respond to this as I am very much in need of this. ASAP.

Thanks,

Charitha Nama





Re: Visual C# Language "object reference is required for the nonstatic field, method, or property 'Namespace1.Class2.Method2(object)"

Mark Dawson

Hi,

if you want some relevant responses, create a new thread with a relevant title.

Mark.