I have a public class A
which contains several methods.
I have two other classes within which I create the object of class A
to call its method say MethodA()
.
Now it is behaving very strangely: when I call MethodA()
from the other two classes it returns the same value to both the classes although the input is different from these classes.
Note my application is in multithreaded environment.
Some illustration of my code is below:
namespace Project1
{
public Class A : SourceClass
{
public string MethodA(string input)
{
//it performs a logic and returns string variable
string str1 = input;
string str2 = "Hello";
string str3 = "";
if(str1.Compare(str2) == 0)
{
str3 = "Same";
}
else
{
str3 = "Different";
}
return str3;
}
public Class B : SourceClass
{
A objA = new A();
string input1 = "Hello";
string str1 = objA.MethodA(input1);
MessageBox.Show(str1 + "from Class B");
}
public Class C : SourceClass
{
A objA = new A();
string input1 = "Hi";
string str1 = objA.MethodA(input1);
MessageBox.Show(str1 + "from Class C");
}
}
Now when I run my application I get output as Same from class B
and Same from class C
, whereas I should get Different from class C
.
Since its a multithreaded environment I think I am missing to lock an object. Please guide me as to where am I going wrong.