I'm scratching my head in trying to get the multithreading to work as I want in WPF
I have an object (with a singleton) called Manager which does alot of processing and lookups. I want it to run in a separate thread from the UI, The UI will call methods on Manager to do the processing and fire events that the UI should react to
I'm converting this app from windows forms where I dont think this was a problem since the textbox event was automatically fired in a different thread. Not so in WPF where everything seems to stay on the UI thread.
How do I make an object "live" in a different thread and then how do I call its methods. I tried spawning it to a new thread using this in the Window constructor
Thread managerThread = new Thread(new ThreadStart(ManagerStartingPoint));
managerThread.SetApartmentState(ApartmentState.STA);
managerThread.IsBackground = true;
managerThread.Start();
and:
private void ManagerStartingPoint()
{
ManagerSingleton.Manager = new Manager();
MediatorSingleton.Mediator = new Mediator();
}
On the textbox textchanged event I call Manager.SetItemText(e.Value) which logically should be called on the new thread right? Still when I type and the event triggers the UI "stutters" and typing in the textbox is affected. Do I need to call the method asynchronously or something?