Current thread must be set to single thread apartment (STA)


https://www.nevron.com/Forum/Topic13110.aspx
Print Topic | Close Window

By Mike O'Ceirin - 4 Years Ago
I am trying to put a chart image into the clipboard. It seems it requires single threading how do I implement this? It occurs in debug mode and also occurs when the asp.net project is published on the net. How can I implement it please.
I get the message in the subject line when I try to run the following code
   protected void ChartClip_Click(object sender, EventArgs e)
   {
    NImageExporter imageExporter = this.chartControl.ImageExporter;
    imageExporter.CopyToClipboard(imageExporter.DefaultImageSize, NResolution.ScreenResolution, new NJpegImageFormat());
   }
By Nevron Support - 4 Years Ago
Hi Mike,

This code will copy the chart image to the clipboard on the server.

In case you want to put the image on the clients' clipboard, you'll need to implement a custom command and custom request. The custom request will send a message to the server to generate a rasterized image, and the custom command will place the rasterized image on the clipboard on the client. Check out the Custom Commands and Custom Requests example. Alternatively, you can simply put a toolbar that allows the user to save the chart image in png or bmp format.

We hope this helps - let us know if you meet any problems or have any questions.
By Mike O'Ceirin - 4 Years Ago
This feature if it is only going to work when one is logged into the server it does not seem to have a lot of point. I thought you might mean it would work for a user directly using the website. I haven't tested it but if it works one would have to be logged into the server and then run it.

I don't want to get involved with creating a new custom control so I will try the toolbar which seemed to me to be somewhat overkill. Providing a facility to use a copy of the chart in other applications for documentation purposes is quite important though.

Thanks for the advice I will add the toolbar.
By Mike O'Ceirin - 4 Years Ago
Yes that is a solution thank you.
By Nevron Support - 4 Years Ago
Hi Mike,
We're glad everything is working properly. Just to clarify on the previous post - the image exporter copy to clipboard feature is used in desktop apps only (WinForms, WPF) and is not intended to work in web forms. If you meet any problems with the proposed solution please let us know.