Hi
i want to take screenshot on button click. Code is working in local but when hosted it doesnt work. It gives JIT error
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Additional information: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application
Please Help.
protected void LinkButton4_Click(object sender, EventArgs e)
{
var t = new Thread((ThreadStart)(() =>
{
using (System.Windows.Forms.SaveFileDialog dlgSave = new System.Windows.Forms.SaveFileDialog())
{
//dlgSave.Title = "Save Image";
dlgSave.Filter = "Bitmap Images (*.bmp)|*.bmp|All Files (*.*)|*.*";
if (dlgSave.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//If user clicked OK, then save the image into the specified file
using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height))
{
Thread.Sleep(2500);
//picturebox1.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bmp as System.Drawing.Image);
graphics.CopyFromScreen(0, 0, 0, 0, bmp.Size);
bmp.Save(dlgSave.FileName);
}
}
}
}));
t.SetApartmentState(ApartmentState.STA);
t.Start();
t.Join();
}