We’re developing an extra web based front end for what was until now a monolithic WPF .Net 4.72 application and want to add a small service that we can host a REST API, that when given a GUID, can render the data into a scichart exported bitmap.
My plan was to use ASP.NET core to do this as the rest of web application will be done using this, but although I can install the scichart package, I can’t find a way to reference the Presentation Core dlls (needed for amongst other things the colors and content control stuff).
The project sdk is Microsoft.NET.Sdk.Web, but I can’t figure out how to do this.
- Brian Dawber asked 3 years ago
- You must login to post comments
Hello. Your article helped me a lot. I am currently writing my master’s thesis. I have difficulty with this. I was advised to find masters assignment writing. I found Assignment Masters service. These guys helped me a lot. Professional writers were always ready to help.
- Alejandro Roberts answered 2 years ago
- last edited 2 years ago
- You must login to post comments
It turns out simpler than I thought I needed to add the following to the project file:
FrameworkReference Include=”Microsoft.WindowsDesktop.App.Wpf
This does mean you will be restricted to running the service on a windows machine though so be aware of that.
Then because the SciChart stuff needs to run in an STA thread (the asp.net core project is MTA). You need to run it in a separate thread in the Get of the controller:
[HttpGet]
public IActionResult Get()
{
byte[] bytes = null;
Thread newWindowThread = new Thread(new ThreadStart(() =>
{
var bs = CreatChart();
var encoder = new PngBitmapEncoder();
using (MemoryStream stream = new MemoryStream())
{
encoder.Frames.Add(BitmapFrame.Create(bs));
encoder.Save(stream);
bytes = stream.ToArray();
stream.Close();
}
}));
// set the apartment state
newWindowThread.SetApartmentState(ApartmentState.STA);
// make the thread a background thread
newWindowThread.IsBackground = true;
// start the thread
newWindowThread.Start();
newWindowThread.Join();
return File(bytes, "image/png");
}
}
- Brian Dawber answered 3 years ago
- last edited 3 years ago
- You must login to post comments
Please login first to submit.