views:

61

answers:

1

Background: We are currently looking at converting a piece of RTF text to a propriety format on a server. We currently have some spike code using the Richtextbox in the System.Windows.Controls namespace to convert the text to xaml and run it through a xslt transform to the required format.

This works fine in the spike but have concerns that running this code in a production windows service may cause some issues down the track.
(We had issues previously on another piece of code that was using the System.Drawing namespace in a windows service).

I was wondering if anyone here would be able to tell me if they have used System.Windows.Controls in anger within a Windows Service and did they find it safe to use. Or if you had any issues, what were they?

A: 

I try to never use any controls in anger. Leads to the Dark Side it does...

UI controls, and their methods, are typically not considered thread safe, so it will be up to you to do any synchronization. Dispose of what needs disposing and be diligent in your testing. You'd probably be ok.

If it has an impact, it would be something insidious and indirect.

For instance, using the XSLT transform you want to load it once and cache the instance. Otherwise, if you use an instance of it every time you need a transform you will generate a bunch of temporary assemblies that will eventually cause an OutOfMemoryException.

The Microsoft KB, PRB: Cannot unload assemblies that you create and load by using script in XSLT has more information regarding this.

Good luck!

Z

EDIT - removed reference to System.Drawing (with its warning) since I misread the original question.
EDIT - added remark about UI controls and threadsafety

Zach Bonham