Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9104623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:54:42+00:00 2026-06-17T01:54:42+00:00

My application runs fine for about 5 minutes, then it will throw some random

  • 0

My application runs fine for about 5 minutes, then it will throw some random System.ArgumentException as seen in the screenshot below:

The big problem here is that both arguments actually seem to be correct, and it works perfectly fine for about 5 minutes.
My application simply keeps taking snapshots of the screen in a separate Thread.

The following code takes the snapshot of the screen, and a System.ArgumentException is caused in this snippet (same as in the screenshot).

Bitmap SNew = new Bitmap(NewRes.Width, NewRes.Height);
using (Graphics g = Graphics.FromImage(SNew))
    g.CopyFromScreen(0, 0, 0, 0, new Size(NewRes.Width, NewRes.Height));

The same exception may also occur at the CopyFromScreen method, with the same seemingly correct NewRes values (while not occuring at the first line in my snippet):

An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll


If I put this code in a try { } catch { } clause, it works fine as well (the exception does not occur anymore after the exception pops up in the log for about 10 times). This is of course not a great solution, and sometimes it just keeps hanging within that exception forever, not taking screenshots at all until I restart the application.

I have no idea why the arguments are invalid and what may cause this. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T01:54:43+00:00Added an answer on June 17, 2026 at 1:54 am

    What I can provide to you with certainty is a concrete alternative that will produce the same output but instead of using CopyFromScreen using platform invoke to interop with the Windows API directly. You can find a full example here, curtosy of Hans Passant as a response to a question here.

    I can’t however, tell you with certainty why you’re experiencing the exception but I can deduce from other sources such as this thread (incidentally featuring Hans again as nobugz) and from my own experiences that CopyFromScreen is buggy and in this case, could be suffering from a memory leak. Considering the thread I linked, what version of the .NET Framework is your target framework?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application witch runs about 30 min. with some input data. It
I have a ASP.NET MVC application using NHibernate and the application runs fine when
I have a web application that runs fine under IIS5 or IIS6. I just
Is it possible that an adobe air application that runs fine with an older
I'm programming a Google Maps based Android application. The application itself runs fine, without
I have a Windows Forms application (.NET 4) that runs fine on my development
I have a web application that runs perfectly fine when I use the Visual
Our application which runs fine on previous versions of TS have a new issue
I've developed a small application in C# (.net 3.5) which runs in the system
I'm working on an application which builds and runs fine in Win32. However, in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.