SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components

0
0

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.

Version
6.3
  • You must to post comments
0
0

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");

    }
}

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.