Click here to Skip to main content
15,879,348 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi In the C# program, I want to call a function to screen capture and save it to the database, when an exception occurs and the program is in a stopped mode.

What I have tried:

Hi
In the C# program, I want to call a function to screen capture and save it to the database, when an exception occurs and the program is in a stopped mode.
Posted
Updated 1-Mar-21 21:41pm
Comments
Richard MacCutchan 23-Feb-21 8:18am    
You could try adding the code to the exception handler, but there is no guarantee that it will not cause further exceptions.
Dave Kreskowiak 23-Feb-21 9:26am    
I think he's trying to handle the case where another app errors out and stops, not his own app.

If your app has stopped, you can't do anything: you need your code running in order to do anything.

So by that time, it;'s too late - the idea is to spot problems before they become fatal, and do something useful then; then continue or fail the app as necessary.

Start by finding out where in yoru code it is failing - use the debugger - and then work out why: is it the screen capture code or the DB INSERT for example. When you know that, you can start working out what to do to prevent it happening in production, either by detecting problems using try...catch in your code, or by ensuring that your code notices a problem before the "outside world" gets involved and handling it then.

Sorry, but we can't do any of that for you - we don't have access to your HDD, we can't see your screen, and we can't read your mind!
 
Share this answer
 
Comments
MehranSarrafi 25-Mar-21 3:08am    
Thanks, but I found that if my app has stopped, I CAN do something
by using multithreading(creating another thread other than the main thread), just before it stops.Please see my answer below.
Thanks, I found out my solution and I write down here; and I hope it will be useful for others.
I catch the exception with try catch block and call my function to do what I need in a new thread; and then throw the exception again with the main thread so that the exception screen is shown. This is the code:
try
{
My code that may encounter exception, goes here.
}
catch (Exception ex)
{
Thread t = new Thread(() => SaveErrorInfo(ex, "some text"));
t.Start();
throw (ex);

}
//My method that will do what I need:
public void SaveErrorInfo(Exception ex,string h_tools_form)
{
Thread.Sleep(2); //Will wait so that the exception is shown.
InsertExceptionInfo(exEntity);// will capture the screen and so on.
Application.Exit();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900