CopyFromScreen - check if handle is vaild
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm capturing screen using CopyFromScreen. When someone locks PC, then it's starting to throw exception System.ComponentModel.Win32Exception (0x80004005): The handle is invalid. To avoid it, I'm checking current session state using SystemState.SessionSwitch. It's a good solution, but when I'm capturing screen with speed 30 screenshots per second, then it is fast enough to fire this exception 1/2 times before I switch flag state in SessionSwitch event. Is there any way to check current session state in catch block or to check if handle is valid before I invoke CopyFromScreen?
c# winapi gdi system.drawing
add a comment |
I'm capturing screen using CopyFromScreen. When someone locks PC, then it's starting to throw exception System.ComponentModel.Win32Exception (0x80004005): The handle is invalid. To avoid it, I'm checking current session state using SystemState.SessionSwitch. It's a good solution, but when I'm capturing screen with speed 30 screenshots per second, then it is fast enough to fire this exception 1/2 times before I switch flag state in SessionSwitch event. Is there any way to check current session state in catch block or to check if handle is valid before I invoke CopyFromScreen?
c# winapi gdi system.drawing
2
Not being able to reliably tell that the user activated the secure desktop is a feature. SessionSwitch squeaked past the security review, somehow, it did get added much later. You might get a better indication from Control.CreateGraphics() producing IntPtr.Zero for the GetHdc() return value. Not sure, try/catch is otherwise as good as it is going to get.
– Hans Passant
Nov 23 '18 at 13:56
Thanks! I'm checking now value from GetHdc() and it seems to be working great! As this answer is in comment I don't know how to mark it as accepted answer. Is it possible in any way :)?
– Hawex
Nov 23 '18 at 14:36
Lucky guess. Be sure to share what you discovered in your own post and mark it as the answer.
– Hans Passant
Nov 23 '18 at 14:39
add a comment |
I'm capturing screen using CopyFromScreen. When someone locks PC, then it's starting to throw exception System.ComponentModel.Win32Exception (0x80004005): The handle is invalid. To avoid it, I'm checking current session state using SystemState.SessionSwitch. It's a good solution, but when I'm capturing screen with speed 30 screenshots per second, then it is fast enough to fire this exception 1/2 times before I switch flag state in SessionSwitch event. Is there any way to check current session state in catch block or to check if handle is valid before I invoke CopyFromScreen?
c# winapi gdi system.drawing
I'm capturing screen using CopyFromScreen. When someone locks PC, then it's starting to throw exception System.ComponentModel.Win32Exception (0x80004005): The handle is invalid. To avoid it, I'm checking current session state using SystemState.SessionSwitch. It's a good solution, but when I'm capturing screen with speed 30 screenshots per second, then it is fast enough to fire this exception 1/2 times before I switch flag state in SessionSwitch event. Is there any way to check current session state in catch block or to check if handle is valid before I invoke CopyFromScreen?
c# winapi gdi system.drawing
c# winapi gdi system.drawing
asked Nov 23 '18 at 13:36
HawexHawex
8810
8810
2
Not being able to reliably tell that the user activated the secure desktop is a feature. SessionSwitch squeaked past the security review, somehow, it did get added much later. You might get a better indication from Control.CreateGraphics() producing IntPtr.Zero for the GetHdc() return value. Not sure, try/catch is otherwise as good as it is going to get.
– Hans Passant
Nov 23 '18 at 13:56
Thanks! I'm checking now value from GetHdc() and it seems to be working great! As this answer is in comment I don't know how to mark it as accepted answer. Is it possible in any way :)?
– Hawex
Nov 23 '18 at 14:36
Lucky guess. Be sure to share what you discovered in your own post and mark it as the answer.
– Hans Passant
Nov 23 '18 at 14:39
add a comment |
2
Not being able to reliably tell that the user activated the secure desktop is a feature. SessionSwitch squeaked past the security review, somehow, it did get added much later. You might get a better indication from Control.CreateGraphics() producing IntPtr.Zero for the GetHdc() return value. Not sure, try/catch is otherwise as good as it is going to get.
– Hans Passant
Nov 23 '18 at 13:56
Thanks! I'm checking now value from GetHdc() and it seems to be working great! As this answer is in comment I don't know how to mark it as accepted answer. Is it possible in any way :)?
– Hawex
Nov 23 '18 at 14:36
Lucky guess. Be sure to share what you discovered in your own post and mark it as the answer.
– Hans Passant
Nov 23 '18 at 14:39
2
2
Not being able to reliably tell that the user activated the secure desktop is a feature. SessionSwitch squeaked past the security review, somehow, it did get added much later. You might get a better indication from Control.CreateGraphics() producing IntPtr.Zero for the GetHdc() return value. Not sure, try/catch is otherwise as good as it is going to get.
– Hans Passant
Nov 23 '18 at 13:56
Not being able to reliably tell that the user activated the secure desktop is a feature. SessionSwitch squeaked past the security review, somehow, it did get added much later. You might get a better indication from Control.CreateGraphics() producing IntPtr.Zero for the GetHdc() return value. Not sure, try/catch is otherwise as good as it is going to get.
– Hans Passant
Nov 23 '18 at 13:56
Thanks! I'm checking now value from GetHdc() and it seems to be working great! As this answer is in comment I don't know how to mark it as accepted answer. Is it possible in any way :)?
– Hawex
Nov 23 '18 at 14:36
Thanks! I'm checking now value from GetHdc() and it seems to be working great! As this answer is in comment I don't know how to mark it as accepted answer. Is it possible in any way :)?
– Hawex
Nov 23 '18 at 14:36
Lucky guess. Be sure to share what you discovered in your own post and mark it as the answer.
– Hans Passant
Nov 23 '18 at 14:39
Lucky guess. Be sure to share what you discovered in your own post and mark it as the answer.
– Hans Passant
Nov 23 '18 at 14:39
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447728%2fcopyfromscreen-check-if-handle-is-vaild%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53447728%2fcopyfromscreen-check-if-handle-is-vaild%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Not being able to reliably tell that the user activated the secure desktop is a feature. SessionSwitch squeaked past the security review, somehow, it did get added much later. You might get a better indication from Control.CreateGraphics() producing IntPtr.Zero for the GetHdc() return value. Not sure, try/catch is otherwise as good as it is going to get.
– Hans Passant
Nov 23 '18 at 13:56
Thanks! I'm checking now value from GetHdc() and it seems to be working great! As this answer is in comment I don't know how to mark it as accepted answer. Is it possible in any way :)?
– Hawex
Nov 23 '18 at 14:36
Lucky guess. Be sure to share what you discovered in your own post and mark it as the answer.
– Hans Passant
Nov 23 '18 at 14:39