Vote count:
0
I have a public class Class A() which contains several method.
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 same value to both the classes although the input is different from theses classes.
**Note my application is in Multi threaded 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))
{
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.
asked 50 secs ago
Aucun commentaire:
Enregistrer un commentaire