i create solidcolorbrush
on non-gui thread, , want pass gui thread display it, invalidoperationexception
: the calling thread cannot access object because different thread owns it.
(even if try freeze();
it). how pass object created in thread x thread y ?
i know can create solidcolorbrush
object in gui thread dispatcher
, complicate everything... want create in worker thread.
additional details:
i initialize static delegate in static class, allow sending messages business layer gui:
public static class gui{ private static printmethoddelegate _printmethod; public static void initializeguiinterface(printmethoddelegate printmethod){ _printmethod = printmethod; } public static void print(guimessage data) { _printmethod(data); } }
initialization (in gui thread):
gui.initializeguiinterface(_messagestouserhandler.printmessage);
then in (non-gui) thread, use it:
gui.print(new guimessage(testdescription) { foreground = new solidcolorbrush(somecolor) });
while guimessage
is:
public class guimessage { public string msg { get; set; } private solidcolorbrush _foregroundbrush; public solidcolorbrush foreground { { return _foregroundbrush; } set { _foregroundbrush = value; } } }
you can create wpf resources in thread if freeze them, after element can passed yet thread or gui thread. remember once frozen object can modified making copy , using copy. can't freeze objects have bindings or animations attached it.
Comments
Post a Comment