Click here to Skip to main content
15,744,193 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I am Using Composite Application Library for My Windows Application Development
and i am Facing problem in Unit Testing
This is what going on
1.I am inheriting the Bootstrapper and running it from by test class and then i will have the Container available to me and now i resolve the required object to test
2. i will test each functionality like initiating the command assigning values to properties etc
the problem occurs in 2
the problem is on assigning value to the property i am calling RaiseCanExecuteChanged() in Delegate Command
it is throwing error as "The calling thread cannot access this object because a different thread owns it."
how do i resolve this issue??
sample code From my Testing Class

public void TestSetup()
_thread = new Thread(new ThreadStart(() =>
_application = new MockApplication();
model = _application.Container.Resolve(typeof(NewCaseViewModel)) as NewCaseViewModel;
public void TestSearchFunctionality()
Assert.True(model != null);
if (model != null)
model.MemberToSearch = "raghu";
if (model.SearchCommand.CanExecute(""))
Assert.True(model.SearchedMembers != null);
here is my code here the nunit framework is calling the test method and i cant make the _thread Execute the line <code>model.MemberToSearch = "raghu";</code>

this is the code written in the Setter of the MemberToSearch Property

<pre lang="cs">
                _memberToSearch = value;

Updated 22-Mar-11 19:49pm
Ghagar 22-Mar-11 11:27am    
please help ASAP :D

1 solution

You should resolve this issue by addressing the object in question in the same thread as the thread used to instantiate it. This could be a matter is simple re-design. Just move the instantiation code in the same thread. (You don't show enough code, but this is a simple as that.)

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900